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

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

string str="NESW";
int change(char ch){
  for(int i=0;i<4;i++)
    if(ch==str[i])return i;
  return 0;
}

int n,m,sx,sy;
int ax,ay,bx,by,d,e,E;
bool t[51][51][4];
bool f[51][51][4];
bool nf[51][51][4];

void solve(bool flg){
  memset(nf,0,sizeof(nf));
  
  for(int x=0;x<=50;x++){
    for(int y=0;y<=50;y++){
      for(int prev=0;prev<4;prev++){
        if(!f[x][y][prev])continue;        
        for(int dir=0;dir<4;dir++){
          if(prev==(dir+2)%4)continue;
          if(!t[x][y][dir])continue;
          if(flg&&prev!=E&&dir!=E)continue;
          int nx=x+dx[dir],ny=y+dy[dir];
          nf[nx][ny][dir]=true;
        }
      }
    }
  }
  
  for(int x=0;x<=50;x++)
    for(int y=0;y<=50;y++)
      for(int prev=0;prev<4;prev++)
        f[x][y][prev]=nf[x][y][prev];
}

int main(){
  cin>>n>>sx>>sy>>m;
  for(int i=0;i<n;i++){
    cin>>ax>>ay>>bx>>by;
    if(ax>bx)swap(ax,bx);
    if(ay>by)swap(ay,by);
    if(ax==bx){
      for(int y=ay;y<=by;y++){
        t[ax][y][0]=(y<by);
        t[ax][y][2]=(y>ay);
      }
    }else{
      for(int x=ax;x<=bx;x++){
        t[x][ay][1]=(x<bx);
        t[x][ay][3]=(x>ax);
      }
    }
  }
  
  for(int i=0;i<4;i++)
    if(t[sx][sy][(i+2)%4])
      f[sx][sy][i]=true;
  
  char ch='N';
  e=-1;
  for(int i=0;i<m;i++){
    cin>>d>>ch;
    E=e;
    e=change(ch);
    for(int j=0;j<d;j++){
      solve(i>0&&j==0);
    }
  }

  vector<P> ans;  
  e=change(ch);
  for(int x=0;x<=50;x++){
    for(int y=0;y<=50;y++){
      bool flg=false;
      for(int z=0;z<4;z++)
        if(f[x][y][z])
          if(z==e||(t[x][y][e]&&(z+2)%4!=e))
            flg=true;
      if(flg)ans.push_back(P(x,y));
    }
  }

  sort(ans.begin(),ans.end());
  for(int i=0;i<(int)ans.size();i++){
    cout<<ans[i].first<<' '<<ans[i].second<<endl;
  }
  return 0;
}

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

int main()
{
    ll a, b;
    cin >> a >> b;

    cout << a * b / __gcd(a, b) << endl;
}

Measured memory_bytes: 3596
using System;

namespace Q2
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string input1 = Console.ReadLine();
            string[] input2 = Console.ReadLine().Split(' ');
            int[] vs = new int[input2.Length];
            for(int i = 0; i < input2.Length; i++)
            {
                vs[i] = Int32.Parse(input2[i]);
            }

            int sum = 0;

            for(int i = 0; i < vs.Length - 1; i++)
            {
                for(int j = i+1; j < vs.Length; j++)
                {
                    sum += vs[i] * vs[j];
                }
            }

            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 11092
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(), (v).end()
int gcd(int a, int b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  int n, x;
  cin >> n >> x;
  int ans;
  cin >> ans;
  ans = abs(ans - x);
  rep(i, n - 1) {
    int a;
    cin >> a;
    a = abs(a - x);
    ans = gcd(ans, a);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    X,K,D=mi()

    if X == 0:
        ans = D if K % 2 == 1 else 0
        print(ans)
        exit()
    
    n = abs(X)//D
    ans = INF
    for n2 in [n-1,n,n+1]:
        m = K-n2

        if X > 0:
            res = X - D*n2
        else:
            res = X + D*n2

        if m <= 0:
            if X > 0:
                res = X - D*K
            else:
                res = X + D*K
            ans = min(ans,abs(res))
            continue


        if m % 2 == 1:
            res = min(abs(res + D), abs(res-D))
        else:
            res = res
        
        ans = min(ans,abs(res))
    
    print(ans)






if __name__ == "__main__":
    main()

Measured memory_bytes: 62056
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 8;
const ll MOD = 1e9 + 7;
const ll LLINF = 1e18;
#define Pint pair<int, int>
#define rng(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rnr(i, a, b) for(ll i = ll(a); i >= ll(b); i--)
#define rep(i, b) rng(i, 0, b)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

ll orimin(ll x, ll y) {
    if(x < 0) x = LLINF;
    if(y < 0) y = LLINF;
    return min(x, y);
}

int main() {
    /*
    int n, m; cin >> n >> m;
    int x[n]; rep(i, n) cin >> x[i];
    */
    ll x, y; cin >> x >> y;
    ll ans = LLINF + 10;
    rep(i, 2) {
        rep(j, 2) {
            ll tmpx = x, tmpy = y, tmpans = 0;
            if(i) tmpx = -tmpx, ++tmpans;
            tmpans += orimin((tmpy - tmpx), (-tmpy - tmpx));
            tmpx += orimin((tmpy - tmpx), (-tmpy - tmpx));
            if(j) ++tmpans, tmpx *= -1;
            if(tmpx == y) ans = min(ans, tmpans);
        }
    }
    cout << ans << endl;
}


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

int main() {
  int N,i,ans=0;
  cin>>N;
  vector<int> a(N);
  for(i=0;i<N;i++)cin>>a[i];
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  for(i=0;i<N;i++){
    if(i%2)ans-=a[i];
    else ans+=a[i];
  }
  cout <<ans <<endl;
}

Measured memory_bytes: 256
from collections import deque

def bfs(si, ei):
  q = deque()
  q.append([si,0])
  done = set([si])
  while len(q) > 0:
    prvi, prvcnt = q.popleft()
    for i in g[prvi]:
      if i in done:
        continue
        
      else:
        if prvcnt + 1 > 2:
          continue
          
        if i == ei: return 'POSSIBLE'
        else:
          q.append([i, prvcnt+1])
          done.add(i)
  return 'IMPOSSIBLE'

N,M = map(int,input().split())
g = {i:[] for i in range(N)}
for _ in range(M):
  a, b = map(int,input().split())
  g[a-1].append(b-1)
  g[b-1].append(a-1)

print(bfs(0,N-1))


Measured memory_bytes: 71044
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
if(a<=b){
    for(int i=0;i<b;i++){
        cout<<a;
        if(i==b-1){
            cout<<endl;
        }
    }
}
else{
    for(int i=0;i<a;i++){
        cout<<b;
        if(i==a-1){
            cout<<endl;
        }
    }
}
    return 0;
}


Measured memory_bytes: 256
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fi first
#define se second
#define mp std::make_pair
#define Pair std::pair<int, int>
#define Map std::map< int, int >
#define Vector std::vector<int>
 
using std::cin;
using std::cout;
using std::endl;
 
typedef long long ll;
typedef unsigned long long ull;
 
const int N = 100000 + 5;
const int M = 1000 + 5;
const int K = 1e7 + 5;
const int MOD = 1e9 + 7;
const int inv2 = 500000004;
const int LOG = 40;
const ull BASE = 19260817;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };
const double PI = acos(-1);
 
template<class T>
inline T readT() {
    T res = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) res = (res << 1) + (res << 3) + ch - '0';
    return res * f;
}
#define read readT<int>

// int n, a[10005], ans;
int n, t, P;
// Pair h[N];

int main() {
    scanf("%d %d %d", &n, &t, &P);
    double tmp = DBL_MAX, gap = DBL_MAX;
    int pos = -1;
    for (int i = 1; i <= n; i++) {
        int x;
        scanf("%d", &x);
        tmp = t - x * 0.006;
        if (std::fabs(tmp - P) < gap) {
            gap = std::fabs(tmp - P);
            pos = i;
        }
    }
    printf("%d\n", pos);
    return 0;
}

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


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

    ll N,A,B;
    cin>>N>>A>>B;
    ll s = A+B , d = N/s ,t = N%s;
    if(t>A) t = A;
    cout<<(d*A+t)<<'\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <array>
#include <stack>
#include <queue>
#include <chrono>
#include <numeric>

#pragma warning(disable:4996)
#define REP(i,n) for(int i = 0 ; i < n ; ++i)
typedef long long Int;

using namespace std;

struct point{
	Int j, i,step;
	point(Int i_, Int j_,Int s) :i(i_), j(j_),step(s){}
};

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

queue<point> que;
char tile[1001][1001];
int H, W;
bool ed[1001][1001];

point solve(char target)
{
	while (!que.empty()){
		point now(que.front());
		//ed[now.i][now.j] = true;
		que.pop();
		REP(i, 4){
			int x = now.j + dx[i];
			int y = now.i + dy[i];

			if (x < 0 || y < 0 || x > W || y > H || ed[y][x])
				continue;

			if (tile[y][x] == target){
				return point(y, x,now.step+1);
			}

			if (tile[y][x] != 'X'){
				que.push(point(y, x, now.step + 1));
				ed[y][x] = true;
			}
		}
	}
}

int main()
{
	cin.tie(0); ios::sync_with_stdio(false);
	//fstream fs("input.txt");
	////////////ここから開始///////////
	int n(0);
	cin >> H >> W >> n;

	REP(i, 1001)REP(j, 1001){ tile[i][j] = 'X'; ed[i][j] = false; }

	REP(i, H)REP(j, W)cin >> tile[i][j];

	REP(i, H)REP(j, W){ if (tile[i][j] == 'S')que.emplace(i, j, 0); }

	for (int i = 0; i < n; ++i){
		REP(i_1, H + 1)REP(j_1, W + 1){ ed[i_1][j_1] = false; }
		point t = solve('1' + i);
		que = {};
		que.emplace(t);
	}

	cout << que.front().step << endl;

	return 0;
}

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

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int i = 0;
    while (a > 0 && c > 0)
    {
        if (i % 2 == 0)
            c -= b;
        else
            a -= d;
        i++;
    }
    if (a > 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3568
#include <set>
#include <cstdio>

using std::multiset;

int main(void)
{
    multiset<double > s;
    int x,N,i;
    double min1,min2,res;
    scanf("%d",&N);
    for(i=0;i<N;i++)
    {
        scanf("%d",&x);
        s.insert(x);
    }
    while( s.size()>1 )
    {
        min1=*(s.cbegin());
        s.erase(s.cbegin());
        min2=*(s.cbegin());
        s.erase(s.cbegin());
        res=(min1+min2)/2;
        s.insert(res);
    }
        printf("%lf\n",res);
    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

int n=9;
map<VI,bool> hs;

bool dfs(VI v) {
	assert(SZ(v)%2==1);
	if (hs.count(v)) {
		return hs[v];
	} else if (SZ(v)==1) {
		return hs[v]=(v[0]==1);
	} else {
		rep(i,0,SZ(v)-2) {
			int cnt=v[i]+v[i+1]+v[i+2];
			VI u=v; u.erase(u.begin()+i,u.begin()+i+3);
			u.insert(u.begin()+i,cnt>=2);
			if (dfs(u)) return hs[v]=1;
		}
		return hs[v]=0;
	}
}

bool check(VI v) {
	int cnt=0;
	VI cand;
	rep(i,0,SZ(v)) {
		cand.pb(v[i]);
		if (SZ(cand)==3) {
			int cnt=cand[0]+cand[1]+cand[2];
			cand.clear(); cand.pb(cnt>=2);
		}
		if (SZ(cand)==1&&cand[0]==1) {
			cnt++;
			cand.clear();
		}
	}
	rep(i,0,cnt) cand.insert(cand.begin(),1);
	if (SZ(cand)==1) {
		return cand[0]==1;
	} else {
		return cand[0]+cand[1]+cand[2]>=2;
	}
}

const int N=301000;
char s[N];
int dp[N][4][4][4],ret;
void upd(int &a,int b) {
	a+=b; if (a>=mod) a-=mod;
}
int main() {
	scanf("%s",s);
	n=strlen(s);
/*	rep(i,0,(1<<n)) {
		VI v;
		rep(j,0,n) v.pb((i>>j)&1);
		ret+=dfs(v);
		assert(dfs(v)==check(v));
	}
	printf("%d\n",ret);*/
//	rep(i,0,n) s[i]='?';
	ret=0;
	dp[0][0][0][0]=1;
	rep(i,0,n) rep(cnt,0,3) rep(sc0,0,3) rep(sc1,0,3) if (dp[i][cnt][sc0][sc1]) {
		int val=dp[i][cnt][sc0][sc1];
		if (s[i]=='0'||s[i]=='?') {
			int nsc0=sc0+1,nsc1=sc1;
			if (nsc0==3) {
				if (nsc1<2) upd(dp[i+1][cnt][1][0],val);
				else upd(dp[i+1][min(cnt+1,2)][0][0],val);
			}
			else upd(dp[i+1][cnt][nsc0][nsc1],val);
		}
		if (s[i]=='1'||s[i]=='?') {
			int nsc0=sc0+1,nsc1=sc1+1;
			if (nsc0==3) {
				if (nsc1<2) upd(dp[i+1][cnt][1][0],val);
				else upd(dp[i+1][min(cnt+1,2)][0][0],val);
			} else if (nsc0==1&&nsc1==1) {
				upd(dp[i+1][min(cnt+1,2)][0][0],val);
			} else {
				upd(dp[i+1][cnt][nsc0][nsc1],val);
			}
		}
	}
	rep(cnt,0,3) rep(sc0,0,3) rep(sc1,0,3) if (dp[n][cnt][sc0][sc1]) { 
		int val=dp[n][cnt][sc0][sc1];
		if (cnt==2) upd(ret,val);
		else {
			int nsc0=sc0+cnt,nsc1=sc1+cnt;
			if ((nsc0==1&&nsc1==1)||(nsc0==3&&nsc1>=2)) upd(ret,val);
		}
	}
	printf("%d\n",ret);
}


Measured memory_bytes: 75520
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int p=998244353;
typedef unsigned long long ull;
int n,len,mx;
long long l,r,siz[110],cnt1[110],cnt2[110],ans[26],sum[110][26];
ull fhash[200010],bhash[200010],bs[200010];
char s[200010];
void solve(long long m,int type){
	for(int i=mx;~i;i--){
		if(m>=siz[i]){
			for(int j=0;j<26;j++)
				ans[j]+=type?sum[i][j]:-sum[i][j];
			m-=siz[i];
		}
	}
	for(int i=1;i<=m;i++)
		ans[s[i]-'a']+=type?1:-1;
	return;
}
int main(){
	scanf("%s%lld%lld",s+1,&l,&r);
	n=strlen(s+1);
	bs[0]=1;
	for(int i=1;i<=n;i++){
		fhash[i]=fhash[i-1]*p+(s[i]-'a'+1);
		bs[i]=bs[i-1]*p;
	}
	for(int i=n;~i;i--)
		bhash[i]=bhash[i+1]+(s[i]-'a'+1)*bs[n-i];
	for(int i=n/2-1;~i;i--)
		if(fhash[i]==bhash[n-i+1]){
			len=i;
			break;
		}
	for(int i=1;i<=n/2;i++)
		sum[0][s[i]-'a']++;
	for(int i=0;i<26;i++)
		sum[1][i]=sum[0][i];
	for(int i=1;i<=n/2-len;i++)
		sum[1][s[i]-'a']++;
	siz[0]=n/2;
	siz[1]=n-len;
	for(int i=2;i<=100;i++){
		for(int j=0;j<26;j++)
			sum[i][j]=sum[i-1][j]+sum[i-2][j];
		siz[i]=siz[i-1]+siz[i-2];
		if(siz[i]>1e18){
			mx=i;
			break;
		}
	}
	solve(l-1,0);
	solve(r,1);
	for(int i=0;i<26;i++)
		printf("%lld ",ans[i]);
	return 0;
}

Measured memory_bytes: 5120
#include "bits/stdc++.h"
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define pi acos(-1.0)
#define ri register int
#define Max(x, y) (((x) > (y)) ? (x) : (y))
#define Min(x, y) (((x) < (y)) ? (x) : (y))
#define Abs(x) ((x) < 0 ? (-(x)) : (x))
#define int long long
#define P std::pair<int, int>
const int maxn = 1e3 + 10;
inline int read()
{
    int f = 1, r = 0;
    char c = getchar();
    while (!isdigit(c)) {
        if (c == '-') {
            f = -1;
        }
        c = getchar();
    }
    while (isdigit(c)) {
        r = 10 * r + c - '0';
        c = getchar();
    }
    return f * r;
}
inline void write(int x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
}
inline void writesp(int x) { write(x), putchar(' '); }
inline void writeln(int x) { write(x), puts(""); }
int H, W, N, cnt[10];
std::set<P> st;
std::map<P, int> mp;
inline int getnum(int row, int col)
{
    int sum = 0;
    for (ri i = 0; i < 3; ++i) {
        for (ri j = 0; j < 3; ++j) {
            int r = row + i, c = col + j;
            P tmp;
            tmp.first = r, tmp.second = c;
            if (st.count(tmp)) {
                sum++;
            }
        }
    }
    return sum;
}
inline void Cal(int row, int col)
{
    for (ri i = 0; i <= 2; ++i) {
        for (ri j = 0; j <= 2; ++j) {
            int x = row - i, y = col - j;
            if (x + 1 > H || x + 2 > H || y + 1 > W || y + 2 > W) {
                continue;
            }
            if (x < 1 || y < 1) {
                continue;
            }
            int fuck = getnum(x, y);
            P tmp;
            tmp.first = x, tmp.second = y;
            if (!mp.count(tmp) && fuck != 0) {
                mp.insert(std::make_pair(tmp, fuck));
            }
        }
    }
}
signed main()
{
    H = read(), W = read(), N = read();
    int zero = (H - 2) * (W - 2);
    for (ri i = 1; i <= N; ++i) {
        P tmp;
        tmp.first = read(), tmp.second = read();
        st.insert(tmp);
    }
    for (std::set<P>::iterator it = st.begin(); it != st.end(); it++) {
        Cal(it->first, it->second);
    }
    for (std::map<P, int>::iterator it = mp.begin(); it != mp.end(); ++it) {
        int tmp = it->second;
        cnt[tmp]++;
    }
    for (ri i = 1; i <= 9; ++i) {
        zero -= cnt[i];
    }
    cnt[0] = zero;
    for (ri i = 0; i <= 9; ++i) {
        writeln(cnt[i]);
    }
    return 0;
}

Measured memory_bytes: 62720
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    int n;
    cin >> n;
    vector<int> v(n, 0), v1(n, 0), v2(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        v1[i] = i;
        v2[i] = i;
    }
    vector<int> s;
    for (int i = 0; i < n; i++) {
        if (s.size() == 0) {
            s.push_back(i);
        } else {
            while (s.size() > 0) {
                int index = s.back();
                if (v[index] > v[i]) {
                    v1[index] = i - 1;
                    s.pop_back();
                } else {
                    break;
                }
            }
            s.push_back(i);
        }
    }
    while (s.size() > 0) {
        v1[s.back()] = n - 1;
        s.pop_back();
    }
    for (int i = n - 1; i >= 0; i--) {
        if (s.size() == 0) {
            s.push_back(i);
        } else {
            while (s.size() > 0) {
                int index = s.back();
                if (v[index] > v[i]) {
                    v2[index] = i + 1;
                    s.pop_back();
                } else {
                    break;
                }
            }
            s.push_back(i);
        }
    }
    while (s.size() > 0) {
        v2[s.back()] = 0;
        s.pop_back();
    }
    long long int res = 0;
    for (int i = 0; i < n; i++) {
        res += (long long int)1 * (v1[i] - i + 1) * (i - v2[i] + 1) * v[i];
    }
    cout << res << endl;
}




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

int main() {
		string S, T;
		cin >> S >> T;
		int T_len = T.size();
		int S_len = S.size();
		int min_len = T_len;
		int flag = 1;
		for (int i = 0; i<S_len;i++) {
				int count = 0;
				for (int j = 0; j < T_len;j++) {
						if (i + j == S_len) {
								flag = 0;
								break;
						}
						if (S.at(i+j) != T.at(j)) {
								count += 1;
						}
				}
				if (flag == 0) {
						break;
				}
				if (count < min_len) {
						min_len = count;
				}
		}
		cout << min_len << endl;
}

Measured memory_bytes: 3488
import java.util.Scanner;

public class Main {
	
	static class P{
		double x, y;
		P(double x, double y){
			this.x=x;
			this.y=y;
		}
	}
	
	static void kock(int n, P p1, P p2) {
		if(n==0) return;
		P s=new P(0.0, 0.0);
		P t=new P(0.0, 0.0);
		P u=new P(0.0, 0.0);
		s.x=(2.0*p1.x+p2.x)/3.0;
		s.y=(2.0*p1.y+p2.y)/3.0;
		t.x=(p1.x+2.0*p2.x)/3.0;
		t.y=(p1.y+2.0*p2.y)/3.0;
		u.x=(t.x-s.x)/2.0 - (t.y-s.y)*Math.sqrt(3.0)/2.0+s.x;
		u.y=(t.x-s.x)*Math.sqrt(3.0)/2.0 + (t.y-s.y)/2.0+s.y;
		
		kock(n-1, p1, s);
		System.out.println(s.x+" "+s.y);
		kock(n-1, s, u);
		System.out.println(u.x+" "+u.y);
		kock(n-1, u, t);
		System.out.println(t.x+" "+t.y);
		kock(n-1, t, p2);
		
	}
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			int n=sc.nextInt();
			System.out.println(0.000000+" "+0.0000000);
			kock(n, new P(0.0, 0.0), new P(100.0, 0.0));
			System.out.println(100.000000+" "+0.000000);
		}
	}
}


Measured memory_bytes: 33268
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, m;
    cin >> n >> m;
    vector<pair<ll, ll>> ab(m);
    rep(i, m) cin >> ab[i].first >> ab[i].second;
    sort(all(ab), [](pair<ll, ll> &a, pair<ll, ll> &b){ return a.second < b.second; });
    ll ans = 0, end = 0;
    rep(i, m) {
        if (ab[i].first >= end) {
            end = ab[i].second;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define ld long double
#define ff first
#define ss second

using namespace std;

int main() {
    int w, s;

    cin >> s >> w;

    if(w >= s) {
        cout << "unsafe" << endl;
    }

    else  {
        cout << "safe" << endl;
    }

    return 0;
}

Measured memory_bytes: 3624
import itertools
N = int(input())
sum = 0
li = [0]*N
for i in range(N):
    li[i] = i+1
li_d = list(map(int, input().split()))
li_comb = list(itertools.combinations(li, 2))
for tpl in li_comb:
    sum += li_d[tpl[0]-1]*li_d[tpl[1]-1]
print(sum)

Measured memory_bytes: 3064
import sys
from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())
def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]
def exit():
    import sys
    sys.exit(0)
def perm_sub(li, used):
    if len(li) == len(used):
        return [deque()]
    k = []
    for i in range(len(li)):
        if i in used:
            continue
        used.add(i)
        sub_list = perm_sub(li, used)
        for sub in sub_list:
            sub.appendleft(li[i])
        k.extend(sub_list)
        used.discard(i)
    return k
def perm_li(li):
    return perm_sub(li, set())
def perm_n(n):
    return perm_sub(list(range(n)), set())
def join_i(li, sep=""):
    return sep.join([str(e) for e in li])
def li2n(li):
    n, base = 0, 1
    for i in range(len(li)-1, -1, -1):
        n += li[i] * base
        base *= 10
    return n
def sli2ili(li):
    return [int(s) for s in li] 

lis = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"
li = [e.strip() for e in lis.split(",")]
k = load() - 1
print(li[k])

Measured memory_bytes: 3436
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

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

ostream& operator << (ostream& os, const mint a) {
    os << a.x;

    return os;
}

const int NMAX = int(1e6);
ll fact[NMAX+1], finv[NMAX+1], inv[NMAX+1];

void comb_init(int N) {
    // init
    REP(i, 2) {
        fact[i] = 1;
        finv[i] = 1;
        inv[i] = 1;
    }

    FOR(i, 2, N+1) {
        fact[i] = fact[i-1] * i % MOD;
        inv[i] = MOD - MOD / i * inv[MOD % i] % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

mint comb(int n, int k) {
    if (n < k || n < 0 || k < 0) return 0;

    return mint(fact[n]) * finv[k] * finv[n-k];
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N, K;
    cin >> N >> K;

    comb_init(N);

    vector<ll> A(N);
    REP(i, N) cin >> A[i];
    sort(A.begin(), A.end());

    debug(A);

    mint ans = 0;

    REP(i, N) {
        ans += comb(i, K-1) * A[i];
        ans -= comb(N-i-1, K-1) * A[i];
    }

    cout << ans.x << endl;
}


Measured memory_bytes: 9984
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; i++) cin >> v[i];
    int m;
    cin >> m;
    vector<int> w(m);
    for(int i = 0; i < m; i++) cin >> w[i];
    vector<int> result;
    set_difference(v.begin(), v.end(), w.begin(), w.end(), back_inserter(result));
    for(int i = 0; i < result.size(); i++) cout << result[i] << endl;
    return 0;
}




Measured memory_bytes: 5428
#include <stdlib.h>
#include <stdio.h>

            
int main(int argc, char** argv) {
    int n1, n2;
    scanf("%d", &n1);
    int arr1[n1+1];
    for(int i=0; i<n1; i++){
        scanf("%d", &arr1[i]);
    }
    
    scanf("%d", &n2);
    int arr2[n2];
    for(int i=0; i<n2; i++){
        scanf("%d", &arr2[i]);
    }
    
    int counter = 0;
    for(int i=0; i<n2; i++){
        arr1[n1+1] = arr2[i]; 
        for(int j=0; j<n1; j++)
            if(arr1[j]==arr1[n1+1]){ 
                counter++;
                break;
            }
    }
    printf("%d\n", counter);
    return 0;
}



Measured memory_bytes: 2128
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pi pair<ll, ll>
#define mp make_pair
#define pb push_back
#define vi vector<ll>
#define pd pair<double, double>
#define vp vector<pi>
#define f(i, n) for(int i = 0; i < n; i++)
#define fo(i, a, n) for(int i = a; i < n; i++)
#define mod (1000*1000*1000+7)
#define sz(x) int((x).size())
#define all(x) x.begin(),x.end()
#define DBG(v) cerr << #v << " = " << (v) << endl;
ll INF = (1ll<<62);

using namespace std;

int main(int argc, char* argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n, k; cin >> n >>k;
	int r= 0;
	f(i, n) {
		int a; cin >> a;
		r = r + (a >= k);
	}cout << r << endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main()
{
    cin>>a>>b>>c;
    if(a-b==b-c)
	{
		cout<<"YES";
	}
    else 
	{
		cout<<"NO";
	}
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  vector<int> x(5);
  for(int i=0;i<5;i++)  cin >> x.at(i);

  for(int i=0;i<5;i++){
    if(x.at(i)==0)  cout << i+1 << endl;
  }

  return 0;
}

Measured memory_bytes: 3564
#include <iostream>
#include <vector>

using namespace std;

const int MOD = 998244353;

long long modPow(long long a, long long p){
    if(p == 0) return 1;
    auto res = modPow(a, p/2);
    res = (res*res)%MOD;
    if(p%2) res = (res*a)%MOD;
    return res;
}

long long calcInv(long long a){
    return modPow(a, MOD-2);
}

int main(){
    const int maxSize = 10000001;
	vector<long long> inv(maxSize);
	vector<long long> fact(maxSize);
	vector<long long> factInv(maxSize);
	for(int i=0;i<2;i++) inv[i] = fact[i] = factInv[i] = 1;
	for(int i=2;i<maxSize;i++){
		inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
		fact[i] = fact[i-1] * i % MOD;
		factInv[i] = factInv[i-1] * inv[i] % MOD;
	}
	auto comb = [&](int n, int r){
		if(n < r || r < 0) return 0LL;
		return fact[n] * factInv[n-r] % MOD * factInv[r] % MOD;
	};
    int N;
    while(cin >> N){
        long long res = modPow(3, N);
        for(int i=N/2+1;i<=N;i++){
            long long sub = comb(N, i) * modPow(2, N-i);
            res = (res + MOD - 2 * sub % MOD) % MOD;
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 234624
#include<bits/stdc++.h>
using namespace std;
long long mask, mod = 1e9+7;
int n;
long long count(vector<vector<long long> > &dp,int msk, int p, vector<vector<bool> > &v){
    if(msk == mask){
      //  cout<<"dddddd "<<endl;
        return 1;
    }
    if(p==n)
        return 0;
    if(dp[msk][p] != -1)
        return dp[msk][p];
    long long ans=0;
    for(int a=0; a<n; a++){

        long long tt = (msk & (1<<a));
       // cout<<p<<" "<<tt<<endl;
        if(tt==0 && v[a][p]){
       //     cout<<"sdfsd "<<endl;
            ans += count(dp,(msk|(1<<a)),p+1,v);
        }
    }
    ans = ans%mod;
    dp[msk][p] = ans;
    return ans;
}

int main()
{
   cin>>n;
   std::vector<vector<bool> > v(n+1, std::vector<bool> (n+1,false));
   for(int a=0; a<n; a++){
    for(int b= 0; b<n; b++){
        int tt;
        cin>>tt;
        if(tt)
            v[a][b] = true;
    }
   }
   mask = (1<<n)-1;

   std::vector<vector<long long> > dp(mask+2, vector<long long> (n+2, -1));
   long long ans = count(dp,0,0,v);
   cout<<ans<<endl;
   return 0;
}

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

constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int A, B;
	cin >> A >> B;
	if (B % A == 0) {
		cout << A + B << endl;
	}
	else {
		cout << B - A << endl;
	}
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
  ll n;cin >>n;
  string s,t; cin >>s>>t;
      for (int i =0; i <n; ++i) {
          string ssub=s.substr(i,n-i);
          string tsub=t.substr(0,n-i);
//          cout <<ssub<<" "<<tsub<<endl;
          if(ssub==tsub){
//              cout <<i<<endl;
              cout <<2*n-(n-i)<<endl;
              return 0;
          }
      }
      cout <<2*n<<endl;
  return 0;
}



Measured memory_bytes: 256
ans = {chr(i): 0 for i in range(97, 97 + 26)}
while True:
    try:
        s = input()
    except BaseException:
        break
    s = s.lower()
    for si in s:
        if si.isalpha():
            ans[si] += 1

for x, y in ans.items():
    print(x, ':', y)



Measured memory_bytes: 5576
#include<iostream>
#include<vector>

int main()
{
	std::vector<bool> vec(30, false);
	for (int i = 0; i != 28; ++i)
	{
		int n;
		std::cin >> n;
		vec[n - 1] = true;
	}

	for (int i = 0; i != 30; ++i)
	{
		if (!vec[i])
			std::cout << i + 1 << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1192
using System;
class Program
{
	static void Main(string[] args)
	{
		string[] input = Console.ReadLine().Split(' ');
		int a = int.Parse(input[0]);
		int b = int.Parse(input[1]);
		int sum = a * b;
        if (sum % 2 == 1)
        {
            Console.WriteLine("Odd");
        }
        else
        {
            Console.WriteLine("Even");
        }
	}
}

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

int main() {
   int N; cin >> N; vector<int> v(2*N); for(int& it : v) cin >> it;
   sort(v.begin(), v.end());
   int rs = 0;
   for(int i = 0; i < 2*N; i += 2) rs += v[i];
   cout << rs << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
using namespace std;

int main()
{
  int n,ans=0,tmp=0;
  string s;
  cin>>n>>s;
  for(int i=0;i<n;i++){
    if(s[i]=='I'){tmp++;}else{tmp--;}
    ans=max(ans,tmp);
  }
  cout<< ans <<endl;
}


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

int main(){
   int w,h,n;  cin >> w >> h >> n;
   int a,x,y;
   int x1max=0,x2min=w,y1max=0,y2min=h;

   for(int i=0;i<n;i++){
      cin  >> x >> y >> a;

      if(a == 1){
         x1max = max(x1max,x);
      }

      if(a == 2){
         x2min = min(x2min,x);
      }

      if(a == 3){
         y1max = max(y1max,y);
      }

      if(a == 4){
         y2min = min(y2min,y);
      }
   }

   w =  x2min - x1max;
   h =  y2min - y1max;

   if(w<0 || h<0){
      cout << 0  <<endl;
      return 0;
   }   
   cout << h*w << endl;


}

Measured memory_bytes: 256
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    const char R = 'R';
    const char G = 'G';
    const char B = 'B';

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());
        var s = input.ReadLine();


        long sum = 0;
        long r = 0;
        long g = 0;
        long b = 0;

        for(int i=0; i<n; i++) {
            var c = s[i];

            if (c == R) r++;
            else if (c == G) g++;
            else if (c == B) b++;

            for(int j=1; j < n-i; j++) {
                if(i+j+j < n) {
                    if(c != s[i+j] && c != s[i+j+j] && s[i+j] != s[i + j + j]) {
                        sum++;
                    }
                }
            }
        }

        return (r * g * b) - sum;
    }
}


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

int main() {
    ll l, r; cin >> l >> r;
    if(r - l >= 2019)
    {
        cout << '0' << endl;
        return 0;
    }
    ll ans = 2020;
    for(ll i = l; i <= r; i++)for(ll j = i+1; j <= r; j++){
        if(i * j % 2019 < ans) ans = i * j % 2019;
    }
    cout << ans << endl;
    return 0;
}


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

int main(void){
  map<string,int>m;
  map<string,int>::iterator it,cit,sit;
  string s;
  int maxS=0,maxC=0;
  while(cin >>s){
    m[s]+=1;
  }
  for(it=m.begin();it!=m.end();it++){
    int size=(*it).first.size();
    if(size>maxS){
      sit=it;
      maxS=size;
    }
    int cou=(*it).second;
    if(cou>maxC){
      cit=it;
      maxC=cou;
    }
  }

  /*
 for(it=m.begin();it!=m.end();it++){
   cout <<(*it).first.size() <<" "<<(*it).second<<endl;
  }
  */
  cout <<(*cit).first <<" "<<(*sit).first<<endl;
}

Measured memory_bytes: 3132
#include<bits/stdc++.h>
#define lli long long int 
#define ll long long 
#define f(i, n) for(int i=0; i<n; i++)

using namespace std;



void test()
{
	
	for(int i=0; i<5; i++)
	{
		int c;
		cin>>c;
		if(c == 0)
		{
			cout<<i+1;
		}
	}
	
}

int main(){
	
	test();
	
	return 0;

}

Measured memory_bytes: 3608
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
using namespace std;

#define ll long long int

int main()
{
    int a, b, c, d;

    cin >> a >> b >> c >> d;
    cout << min(a, b) + min(c, d) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

int main() {
	int n, m;

	for (int i = 0; i < 3; i++) {
		int a, b, c;
		cin >> a >> b >> c;

		if (!i) {
			n = abs(a - b);
			m = abs(b - c);
		}
		else {
			if ((n != abs(a - b)) || (m != abs(b - c))) {
				cout << "No" << endl;
				return 0;
			}
		}
	}

	cout << "Yes" << endl;
}

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

using namespace std;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

int a, b, c, d;

int main()
{
	a = gi();
	for (int i = 1; i <= a; i+=1)
	{
		double x = 1. * i * 1.08;
		if ((int)(x) == a) {printf("%d\n", i); return 0;}
	}
	puts(":(");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
int main() {
    int a, b, c, d, e, f, g, h, i;
    cin >> a >> b >> c >> d >> e >> f >> g >> h >> i;
    bool ans = 1;
    ans &= (d - a == e - b);
    ans &= (e - b == f - c);
    ans &= (g - d == h - e);
    ans &= (h - e == i - f);
    ans &= (b - a == e - d);
    ans &= (e - d == h - g);
    ans &= (c - b == f - e);
    ans &= (f - e == i - h);
    cout << (ans ? "Yes" : "No") << endl;
}
/*
a b c
d e f
g h i
*/

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int a,b,c,d;
   while(~scanf("%d%d%d",&a,&b,&c))
   {
       swap(a,b);
       swap(a,c);
       printf("%d %d %d\n",a,b,c);
   }
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <tuple>
#include <cstring>
#include <map>
#include <iomanip>
#include <ctime>
#include <complex>
#include <cassert>
#include <climits>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define len(X) (X).size()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Tiii tuple<int, int, int>
#define Tlll tuple<ll, ll, ll>

vector<vector<int>> G;
vector<bool> vis;
vector<int> rt;
bool ok = 0;

void dfs(int u, int v) {
    vis[u] = 1;
    if (u == v || ok) {
        ok = 1; return;
    }
    for (int i = 0; i < G[u].size(); i++) {
        if (!ok && G[u][i] != -1 && !vis[i]) {
            rt.push_back(G[u][i]);
            dfs(i, v);
            if (!ok) rt.pop_back();
        }
    }
}

void route(int u, int v) {
    rt.clear();
    vis.assign(G.size(), 0);
    ok = 0;
    dfs(u, v);
}


int main() {
    int n;
    cin >> n;
    vector<int> g(n, -1);
    G.assign(n, g);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--;  b--;
        G[a][b] = G[b][a] = i;
    }
    int m;
    cin >> m;

    bool b[m][n] = {};
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        u--;  v--;
        route(u, v);
        for (auto j : rt) b[i][j] = 1;
    }

    ll ans = (1LL << (n - 1)), mn = 1;
    for (int i = 1; i <= m; i++) {
        mn *= -1;
        vector<int> v;
        for (int j = 0; j < i; j++) v.push_back(0);
        for (int j = i; j < m; j++) v.push_back(1);

        do {
            bool c[n] = {};
            for (int j = 0; j < m; j++) {
                if (!v[j]) {
                    for (int k = 0; k < n - 1; k++) {
                        c[k] |= b[j][k];
                    }
                }
            }

            int cnt = 0;
            for (int j = 0; j < n - 1; j++) cnt += !c[j];
            ans += mn * (1LL << cnt);
            //cerr << c[0] << c[1] << c[2] << c[3] << " ";
            //cerr << v[0] << v[1] << v[2]  _ ans _ cnt << endl;
        } while (next_permutation(all(v)));
        //cout << ans << endl;
    }
    cout << ans << endl;



}


Measured memory_bytes: 256
//	ZapZu's code hohoho
//	#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define dfs_black 1
#define dfs_white -1
#define pr pair
#define vt vector
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef double db;
typedef long long li;
typedef long double ld;

typedef pr<int, int> ii;
typedef pr<ld,ld> dd;

typedef vt<int> vi;
typedef vt<li> vli;
typedef vt<ld> vld;
typedef vt<ii> vii;

typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef map<int, char> mic;

typedef set<int> s_i;
typedef set<char> s_c;

const int MOD = 1e9+7;
const li INF = 1e18;
const ld PI = 4*atan((ld)1);
vi G[200005];
int dp[200005];
int n;
void dfs(int u, int p)
{
	int cnt=0;
	for(auto v: G[u])
	{
		if(v==p) continue;
		dfs(v,u);
		if(!dp[v]) cnt++;
		dp[u]+=dp[v];
	}
	dp[u]+=max(cnt-1, 0);
}
int solve(int root)
{
	for(int i=1; i<=n; i++) dp[i]=0;
	dfs(root, 0);
	return dp[root]+1;
}
signed main()
{
//	freopen("1_13.txt", "r", stdin);
//	freopen(".out", "w", stdout);
	cin>>n;
	if(n<3) return cout<<1, 0;
	for(int i=1; i<=n-1; i++)
	{
		int u, v;
		cin>>u>>v;
		u++;
		v++;
		G[u].eb(v);
		G[v].eb(u);
	}
	vi v;
	for(int i=1; i<=n; i++)
	{
		if(G[i].size()==1) v.eb(i);
	}
	int cnt=0, ans=INT_MAX;
	for(auto temp: v)
	{
		ans=min(ans, solve(temp));
		cnt++;
		if(cnt>=200) break;
	}
	cout<<ans;
}




Measured memory_bytes: 19556
n = int(input())

a = [0] * n
sl = []

for i in range(n):
  a = int(input())
  s = []
  for j in range(a):
    x, y = map(int, input().split())
    s.append([x, y])
  sl.append(s)
ans = 0

# bit 全探索
# 1 = 正直者、0 = 不親切な人
for i in range(1 << n):
  #print('pattern', bin(i))
  all_ok = True
  for j in range(n):
    # 人j が正直者かどうか
    #print('j : {}'.format(j))
    if i & (1 << j):
      # print(j)
      # 正直者であれば証言に矛盾があってはいけない
      s = sl[j]
      for k in range(len(s)):
        target =  s[k][0]
        kind = s[k][1]
        # print('target {} : kind {}'.format(target, kind))
        #print(target, kind, i & (1 << (target-1)), bool(i & (1 << (target-1))), bool(kind))
        rk = 1 if (i & (1 << (target-1))) > 0 else 0
        if rk != kind :
          #print('証言NG')
          # 証言がNG
          all_ok = False
          break
    if not all_ok:
      break
  else:
    # すべての正直者に矛盾がないパターン
    #print('ok', bin(i))
    ans = max(ans, bin(i).count('1'))
    
#print(sl)
print(ans)

Measured memory_bytes: 44400
#include<bits/stdc++.h>
    using namespace std;
    int dp[3007][3007];
    int l,r;
    string str1,str2;
    int f(int i,int j)
    {
    if(i>=l||j>=r)
    return 0;
    if(dp[i][j]!=-1)
    return dp[i][j];
    int a=0;
    if(str1[i]==str2[j])
    a=f(i+1,j+1)+1;
    return dp[i][j]=max({a,f(i+1,j),f(i,j+1)});
    }
    int main()
    {
    cin>>str1>>str2;
    l=str1.size();
    r=str2.size();
    int i,j;
    for(i=0;i<=l+4;i++)
    for(j=0;j<=r+4;j++)
    dp[i][j]=-1;
    int a=f(0,0);
    vector<char> v;
    /*for(i=0;i<l;i++){
    for(j=0;j<r;j++)
    cout<<dp[i][j]<<" ";
    cout<<"\n";}cout<<"\n\n";*/
    i=0;j=0;
    while(i<l&&j<r)
    {
    //cout<<i<<" "<<j<<"\n";
    if(str1[i]==str2[j])
    {
    v.push_back(str1[i]);
    //cout<<" match "<<"\n";
    i++;j++;
    }
    else{
    if(dp[i+1][j]>dp[i][j+1]||j==r-1)
    i++;
    else if(dp[i][j+1]>=dp[i+1][j]||i==l-1)
    j++;
    }
    }
    for(auto x:v)
    cout<<x;
    return 0;
    }

Measured memory_bytes: 35968
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
{
    int N;
    cin >> N;
    int arr[3] , dp[3] = { 0 };
    for (int i = 0; i < 3; i++) dp[i] = 0;
    for (int i = 0; i < N; i++){
        int new_dp[3] = { 0 };
        for (int j = 0; j < 3; j++){
            cin >> arr[j];
        }
        for (int j = 0; j < 3; j++){
            for (int k = 0; k < 3; k++){
                if (j != k)
                new_dp[k] = max(new_dp[k], dp[j] + arr[k] );
            }
        }
        dp[0] = new_dp[0];
        dp[1] = new_dp[1];
        dp[2] = new_dp[2];
    }
    cout << max(dp[0], max(dp[1], dp[2]));

    return 0;
}

Measured memory_bytes: 256