akhauriyash/Code-Regression huggingface dataset:
//g++ t.cpp -o t && t < p.txt
//d>p.txt&&t<p.txt&&t2<p.txt

#include <iostream> // プログラムの耳と口
#include <vector> // 超有能配列秘書
#include <algorithm> // みんな大好きソートと二分探索
#include <queue> // きゅーちゃん、だいすき
#include <string> // to_string
#include <functional> // 関数を変数に入れる子
#include <set> // 値の取得・挿入・削除を高速に
#include <map> // setの妹 これまた優秀
#include <random> // 乱択さん
#include <ctime>
#include <bitset>

#define DB cerr<<"D"<<endl
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";};
using P=pair<ll,ll>;
const ll M = 1e9+7;
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;}; template<typename T, typename U> void chmin(T& x, U y) {if (x>y) x=y;}
bool vaild(int x, int y, int hh, int ww){return 0<=x&&x<hh&&0<=y&&y<ww;}
int keta(ll a) {int res=0; while(a>0) res+=a%10, a/=10; return res;}
const int up[]={1,-1,0,0}, lf[]={0,0,1,-1};
ll gcd(ll a, ll b) {if (b==0) return a; else return gcd(b, a%b);}

int main() {
  ll s; cin>>s;
  ll dp[s+1]={1};
  for(int i=0;i<=s;i++) {
    for(int j=i+3;j<=s;j++) {
      add(dp[j],dp[i]);
    }
  }
  cout<<dp[s]<<endl;
}
// ・配列の大きさok？　・priority_queueはgreater？　・debug消した？
// ・落ち着いて。提出まで4分待ってね……WJ……1/10……2/10……

// Thank you for making problems and running the contest


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <cctype>  // std::islower(), std::isupper(), std::tolower, std::toupper
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;

int main (void) {
  int X, A, B; std::cin >> X >> A >> B;
  std::cout << (X-A)%B << std::endl;
  return 0;
}


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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define all(x) x.begin(), x.end()
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define M 1000000007
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m) {
  int ret = n % m;
  if (ret < 0) ret += m;
  return ret;
}

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

struct Vector2D {
  int x, y;
  Vector2D() {}
  Vector2D(int x, int y) : x(x), y(y) {}

  bool operator<(Vector2D v) const { return tie(x, y) < tie(v.x, v.y); }
  bool operator==(Vector2D v) const { return tie(x, y) == tie(v.x, v.y); }
  bool operator>(Vector2D v) const { return tie(x, y) > tie(v.x, v.y); }
  bool operator<=(Vector2D v) const { return tie(x, y) <= tie(v.x, v.y); }
  bool operator>=(Vector2D v) const { return tie(x, y) >= tie(v.x, v.y); }

  Vector2D normalize() {
    if (x == 0) {
      return Vector2D(0, 1);
    }
    if (y == 0) {
      return Vector2D(1, 0);
    }
    int g = gcd(x, y);
    Vector2D norm(x / g, y / g);
    if (norm.y < 0) norm.x = -norm.x, norm.y = -norm.y;
    return norm;
  }
  Vector2D normalized_orthogonal() {
    if (x == 0) {
      return Vector2D(1, 0);
    }
    if (y == 0) {
      return Vector2D(0, 1);
    }
    int g = gcd(x, y);
    Vector2D ort = Vector2D(-y / g, x / g);
    if (ort.y < 0) ort.x = -ort.x, ort.y = -ort.y;
    return ort;
  }
};

void solution() {
  map<Vector2D, int> m;
  int n;
  cin >> n;
  int pot2[n + 1];
  pot2[0] = 1;
  for (int i = 1; i <= n; i++) pot2[i] = mod(pot2[i - 1] * 2LL, M);
  int lixo = 0;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      lixo++;
      continue;
    }
    Vector2D vec(a, b);
    vec = vec.normalize();
    m[vec]++;
  }
  set<Vector2D> vis;
  int ans = 1LL;
  for (auto p : m) {
    auto vec = p.ff;
    int cnt = p.ss;
    if (vis.count(vec.normalized_orthogonal())) continue;
    vis.insert(vec);
    ans = mod(
        ans * mod(pot2[cnt] + pot2[m[vec.normalized_orthogonal()]] - 1LL, M),
        M);
  }
  ans = mod(ans + lixo - 1LL, M);
  cout << ans << endl;
}

int32_t main() {
  DESYNC;
  solution();
}


Measured memory_bytes: 42564
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
ll INF = 1000000009;
int main()
{
  int n,m;
  cin >> n >> m;
  vector<pair<int,int>> ab,cd;
  rep(i,n){
    int a, b;
    cin >> a >> b;
    ab.emplace_back(a, b);
  }
  rep(i,m){
    int c,d;
    cin >> c >> d;
    cd.emplace_back(c, d);
  }
  rep(i,n){
    ll tmp = INF*INF;
    int num = 0;
    rep(j, m)
    {
      int d = abs(cd[j].first - ab[i].first) + abs(cd[j].second - ab[i].second);
      if (tmp > d)
      {
        tmp = d;
        num = j;
      }
    }
    cout << num + 1 << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
 
using namespace std;

int binpow(int,int);
void dfs( vector< vector<int> >&, int , vector<int>& );
void bfs( vector< vector<int> >&, int , vector<int>& );

void solve()
{
    int r;
    cin>>r;

    cout<<2*(3.141592653589793238)*r<<endl;
}

signed main()
{
    fast;
    int t = 1;
    // cin>>t;
    
    while(t--)
    {
        solve();
    }
    return 0;
}

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

void dfs ( vector< vector<int> > &v , int x , vector<int> &vis )
{
    vis[x] = 1;

    rep(i,0,v[x].size())
    {
        if( vis[v[x][i]] == 0 )
        {
            dfs(v,v[x][i],vis);
        }
    }
}

void bfs( vector< vector<int> > &v , int x , vector<int> &vis )
{
    queue<int> q;
    q.push(x);

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

        rep(i,0,v[p].size())
        {
            if ( vis[v[p][i]] == 0 )
            {
                vis[v[p][i]] = 1;
                q.push(v[p][i]);
            }
        }
    }
}

Measured memory_bytes: 3844
#include<stdio.h>
#define MAX 100000
#define NIL -1

struct Node{
  int left;
  int right;
  int parent;
};

struct Node Tree[MAX];

void Preorder(int);
void Inorder(int);
void Postorder(int);

int main(){
  int n, i;
  int id,l,r,root;

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++){
    Tree[i].parent = NIL;
  }

  for(i = 0 ; i < n ; i++){
    scanf("%d %d %d",&id, &l, &r);
    Tree[id].left = l;
    Tree[id].right = r;
    if(l != NIL) Tree[l].parent = id;
    if(r != NIL) Tree[r].parent = id;
  }

  for(i = 0 ; i < n ; i++) if(Tree[i].parent == NIL) root = i;

  printf("Preorder\n");
  Preorder(root);
  printf("\n");

  printf("Inorder\n");
  Inorder(root);
  printf("\n");

  printf("Postorder\n");
  Postorder(root);
  printf("\n");

  return 0;
}

void Preorder(int x){
  if(x == NIL) return;
  printf(" %d",x);
  Preorder(Tree[x].left);
  Preorder(Tree[x].right);
}

void Inorder(int x){
  if(x == NIL) return;
  Inorder(Tree[x].left);
  printf(" %d",x);
  Inorder(Tree[x].right);
}

void Postorder(int x){
  if(x == NIL) return;
  Postorder(Tree[x].left);
  Postorder(Tree[x].right);
  printf(" %d",x);
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
#define RI(x) x = rit()
#define RII(a,b) a = rit(), b = rit()
#define RIII(a,b,c) a = rit(), b = rit(), c = rit()
#define REP(I, N) for(int I=0;I<int(N);I++)
#define REPP(I, N) for(int I=1;I<=int(N);I++)
#define ll long long
#define SZ(x) (int)(x).size()
#define F first
#define S second
#define PB(x) push_back(x)
inline int rit(){
    int f=0,key=1;
    char ch;
    do{
        ch = getchar();
        if(ch=='-') key=-1;;
    }while(ch<'0'||ch>'9');
    do{
        f = f*10+ch-'0';
        ch = getchar();
    }while(ch>='0'&&ch<='9');
    return f*key;
}
using namespace std;
typedef pair<int,int> P;
int n,num;
vector<int> ar;
int main(void){
	RI(n);
	REP(i,n){
		RI(num);
		ar.push_back(num);
	}
	ar.resize( unique( ar.begin(), ar.end() ) - ar.begin() );
	if(SZ(ar)==1) puts("1");
	else{
		int ans=1, sts;
		sts = ar[1]>ar[0]?1:-1;
		for(int i=2;i<SZ(ar);++i){
			if(ar[i]<ar[i-1]&&sts==1){
				ans++;
				if(i+1<SZ(ar)){
					if(ar[i+1]>ar[i]) sts=1;
					else sts=-1;
				}
			}
			else if((ar[i]>ar[i-1]&&sts==-1)){
				ans++;
				if(i+1<SZ(ar)){
					if(ar[i+1]>ar[i]) sts=1;
					else sts=-1;
				}
			}
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 892
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

void main() {
  auto s = readln.strip.splitter;
  immutable int n = s.front.to!int;s.popFront;
  immutable int m = s.front.to!int;
  int problems, penalty;
  int[int] c;
  bool[int] d;
  foreach (qid; 0 .. m) {
    s = readln.strip.splitter;
    immutable int k = s.front.to!int;s.popFront;
    bool ac = s.front.front == 'A';
    if (ac) {
      auto ptr = k in d;
      if (ptr is null) {
        ++problems;
        int t = c.get (k, 0);
        penalty += t;
        d[k] = true;
      }
    } else {
      c[k] = c.get (k, 0) + 1;
    }
  }
  writeln (problems, ' ', penalty);
}



Measured memory_bytes: 7676
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline ll getint() {
	ll A = 0;
	int k = 10;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= 'a') A = (A << 5) + ct - '`', k--;
	else while ((ct = *ci++) >= 'a') A = (A << 5) + ct - '`', k--;
	A <<= k * 5;
	return A;
}

char D[2200010];
char *di = D;
void pakuri_sort(int N, ll A[]) {
	const int b = 9;
	ll tmp[200001];
	rep(k, 6) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}

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


	fread_unlocked(cn, 1, cm, stdin);
	int N = 0;
	while ((ct = *ci++) >= '0') N = N * 10 + ct - '0';

	ll S[200000];
	rep(i, N) S[i] = getint();
	pakuri_sort(N, S);
	int kazu = 0;
	int saidai = 1;
	ll mae = 0;
	rep(i, N) {
		if (S[i] != mae) {
			if (saidai < kazu) {
				saidai = kazu;
				di = D;
			}
			if (saidai == kazu) {
				ll s = S[i - 1];
				for (ll m = 45; s; s &= ~(31ll << m), m -= 5) {
					*di++ = (s >> m) + '`';
				}
				*di++ = '\n';
			}
			kazu = 1;
			mae = S[i];
		}
		else kazu++;
	}
	if (saidai < kazu) {
		saidai = kazu;
		di = D;
	}
	if (saidai == kazu) {
		ll s = S[N - 1];
		for (ll m = 45; s; s &= ~(31ll << m), m -= 5) {
			*di++ = (s >> m) + '`';
		}
		*di++ = '\n';
	}
	fwrite(D, 1, di - D, stdout);

	Would you please return 0;
}

Measured memory_bytes: 6912
#include<stdio.h>
  
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define NIL -1
#define INF 100000

int n,G[MAX][MAX];

int prim(){
  int u,mincost,i;
  int d[MAX],pi[MAX],color[MAX];
  
  for( u = 0 ; u < n ; u++ ){
    d[u] = INF;
    pi[u] = NIL;
    color[u] = WHITE;
  }
  
  d[0] = 0;
  
  while(1){
    mincost = INF;
    i = NIL;
    for( u = 0 ; u < n ; u++ ){
      if(color[u] != BLACK && d[u] < mincost){
    i = u;
    mincost = d[u];
      }
    }
  
    if( i == NIL ) break;
  
    color[i] = BLACK;
  
    for( u = 0 ; u < n ; u++ ){
      if(color[u] != BLACK && G[i][u] != INF ){
    if( d[u] > G[i][u] ){
      d[u] = G[i][u];
      pi[u] = i;
      color[u] = GRAY;
    }
      }
    }
  }
  
  int sum = 0;
  
  for( u = 0 ; u < n ; u++ ){
    if( pi[u] != NIL ) sum += G[u][pi[u]];
  }
  
  return sum;
} 

  
int main(){
  int i,j,m;
  scanf("%d",&n);
  
  for( i = 0 ; i < n ; i++ ){
    for( j = 0 ; j < n ; j++ ){
      scanf("%d",&m);
      if(m==NIL) G[i][j]=INF;
      else G[i][j]=m; 
    }
  }
  
  printf("%d\n",prim());
  
  return 0;
}
  

Measured memory_bytes: 2680
import java.util.Scanner;

class Main
{
	static final int dx[] = {  0,  1,  0, -1};
	static final int dy[] = { -1,  0,  1,  0};

	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		
		LOOP1: while(true)
		{
			int h = sc.nextInt();
			int w = sc.nextInt();
			
			if (h == 0 && w == 0) break;
			
			sc.nextLine();
			String map[] = new String[h];
			for (int i = 0; i < h; i++)
			{
				map[i] = sc.nextLine();
			}
			boolean visited[][] = new boolean[w][h];
			
			int x = 0;
			int y = 0;
			
			while (map[y].charAt(x) != '.')
			{
				visited[x][y] = true;
				int d = charToDirect(map[y].charAt(x));
				x += dx[d];
				y += dy[d];
				if (visited[x][y])
				{
					System.out.println("LOOP");
					continue LOOP1;
				}
			}
			System.out.println(Integer.toString(x) + " " + Integer.toString(y));
		}
	}
	private static int charToDirect(char c)
	{
		switch (c)
		{
		case '^':
			return 0;
		case '>':
			return 1;
		case 'v':
			return 2;
		case '<':
			return 3;
		}
		return -1;
	}
}

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

using namespace std;

bool ds[10];

bool judge(int x) {
    if(x==0) return true;
    if(ds[x%10]) return false;
    return judge(x/10);
}

int main() {
    int n, k;
    cin >> n >> k;
    for(int i=0; i<k; i++) {
        int d;
        cin >> d;
        ds[d] = true;
    }
    for(int r=n; ;r++) {
        if(judge(r)) {
            cout << r << endl;
            break;
        }
    }
}

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

#define println(msg) cout << msg << endl
#define yes_or_no(flag) if (flag) { println("Yes"); } else { println("No"); }
#define sort_vec(vec) sort(vec.begin(), vec.end())
#define rsort_vec(vec) sort(vec.rbegin(), vec.rend())

int main() {
  // 入力
  int N;
  cin >> N;
    
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  
  // 計算
  rsort_vec(a);
  
  int a_sum = 0;
  int b_sum = 0;
  for (int i = 0; i < a.size(); i += 2) {
    a_sum += a.at(i);
    if (i + 1 < a.size())
      b_sum += a.at(i + 1);
  }
  
  // 出力
  println((a_sum - b_sum));
}

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

int main() {
    int H, W, K; cin >> H >> W >> K;
    vector<vector<int>> G(H, vector<int>(W, 0)), Z;
    rep(i,H) rep(j,W) {
        char c; cin >> c;
        G[i][j] = (c == '.') ? 0 : 1;
    }
    Z = G;
    int res = 0;
    for (int bit = 0; bit < 1 << H+W; bit++) {
        for (int i = 0; i < H+W; i++) {
            if (bit & 1 << i) {
                if (i < W) {
                    rep(j, H) G[j][i] = 3;
                } else {
                    rep(j, W) G[i - W][j] = 3;
                }
            }
        }
        int sum = 0;
        rep(i,H) rep(j,W) if (G[i][j] == 1) sum++;
        if (sum == K) res++;
        G = Z;
    }
    cout << res << endl;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N, M;
    cin >> N >> M;
    set<ll> a;
    REP(i, M){
    	ll tmp;
    	cin >> tmp;
    	a.insert(tmp);
    }

    ll dp[101010];
    REP(i, 101010) dp[i] = 0;
    dp[0]= 1;
    REP(i, N){
    	if(a.find(i) != a.end()) continue;
    	dp[i+1] += dp[i];
    	dp[i+1] %= mod;
    	dp[i+2] += dp[i];
    	dp[i+2] %= mod;
    }
    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 5760
#include <cstdio>
#include <algorithm>

using namespace std;

int main(){
    int a, b, k;
    scanf("%d %d %d",&a, &b, &k);

    int c = min(a, b);
    int count = 0;
    int ans;
    for(int i = c; i >= 1; i--){
        if(a % i == 0 && b % i == 0){
            count++;
            if(count == k){
                ans = i;
                break;
            }
        }
    }
    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 128
program shuffling
  implicit none
  integer(8), parameter :: md = 1000000007_8
  integer :: n, m, i, j, k, l, r, x(0:3001) = 0, c(0:3001) = 0
  character(3001) :: s
  integer(8) :: dp(0:3001,0:3001) = 0_8
  read(*,*) n, m
  read(*,*) s
  s(n+1:n+1) = "0"
  do i = 1, m
    read(*,*) l, r
    x(l) = max(x(l),r)
  end do
  do i = 1, n+1
    x(i) = max(x(i-1),x(i),i)
    c(i) = c(i-1)+ichar(s(i:i))-48
  end do
  dp(1,c(x(1))) = 1_8
  do i = 1, n
    k = c(x(i+1))-c(x(i))
    dp(i+1,k) = mod(dp(i+1,k)+dp(i,0),md)
    do j = 1, n-k
      dp(i+1,k+j-1) = mod(dp(i+1,k+j-1)+dp(i,j),md)
      if (x(i)-i >= j) dp(i+1,k+j) = mod(dp(i+1,k+j)+dp(i,j),md)
    end do
  end do
  write(*,'(i0)') dp(n+1,0)
end program shuffling

Measured memory_bytes: 70656
import kotlin.math.*

fun str() = readLine()!!
fun int() = readLine()!!.toInt()

fun main() {
	val m = hashMapOf<String,Int>()

	for(i in 1..int())
		m.merge(str(),1) {a,b-> a+b}
	for(i in 1..int())
		m.merge(str(),-1) {a,b-> a+b}

	println(max(0,m.values.max()!!))
}


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

const int MOD = (int)1e9+7;

int main(){
	int N;
	cin >> N;
	string S1,S2;
	cin >> S1 >> S2;

	int i=0;
	long long ans;
	if(S1.at(0)==S2.at(0)){
		ans=3;
		i=1;
	}
	else{
		ans=6;
		i=2;
	}
	for(;i<N;i++){
		if(S1.at(i-1)==S2.at(i-1)){
			if(S1.at(i)==S2.at(i))	ans=(ans*2)%MOD;
			else{
				ans=(ans*2)%MOD;
				i++;
			}
		}
		else{
			if(S1.at(i)==S2.at(i))	ans=ans;
			else{
				ans=(ans*3)%MOD;
				i++;
			}
		}
	}
	cout << ans << endl;

	return 0;
}


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

int group(int n) {
    if (n==2) {
        return 0;
    }
    else if (n==4 || n==6 || n==9 || n==11) {
        return 1;
    }
    else {
        return 2;
    }
}


int main() {
    int x, y;
    cin >> x >> y;
    int xx = group(x);
    int yy = group(y);
    if (xx==yy) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

int main(void){
    
    int H,W;
    cin >> H >> W;
    char s[H][W];
    
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> s[i][j];
        }
    }
    
    for(int i=0;i<W+2;i++){
        if(i == W+1) cout << '#' <<endl;
        else cout << '#';
    }
    
    for(int i=0;i<H;i++){
        for(int j=-1;j<=W;j++){
            if(j == -1) cout << '#';
            else if(j == W) cout << '#' <<endl;
            else cout << s[i][j];
        }
    }
    
    for(int i=0;i<W+2;i++){
        if(i == W+1) cout << '#' <<endl;
        else cout << '#';
    }
}

Measured memory_bytes: 3556
#include <iostream>

using namespace std;

const int Nmax = 2005;
int n, m, q, Sum, S1, S2, i, j, ans, sum[Nmax][Nmax], s1[Nmax][Nmax], s2[Nmax][Nmax], x1, x2, y1, y2;
char a[Nmax][Nmax];

int main()
{
    cin.sync_with_stdio(false);
   // freopen("input", "r", stdin);

    cin >> n >> m >> q;

    for(i=1; i<=n; ++i)
    {
        cin >> (a[i]+1);
        Sum = S1 = S2 = 0;

        for(j=1; j<=m; ++j)
        {
            if(a[i][j] == '1')
            {
                ++Sum;
                S1 += (a[i][j-1]=='1');
                S2 += (a[i-1][j]=='1');
            }

            sum[i][j] = sum[i-1][j] + Sum;
            s1[i][j] = s1[i-1][j] + S1;
            s2[i][j] = s2[i-1][j] + S2;
        }
    }

    while(q--)
    {
        cin >> x1 >> y1 >> x2 >> y2;
        ans = sum[x2][y2] - sum[x1-1][y2] - sum[x2][y1-1] + sum[x1-1][y1-1];
        ans -= s1[x2][y2] - s1[x1-1][y2] - s1[x2][y1] + s1[x1-1][y1];
        ans -= s2[x2][y2] - s2[x1][y2] - s2[x2][y1-1] + s2[x1][y1-1];
        cout << ans << '\n';
    }

    return 0;
}


Measured memory_bytes: 52864
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    long n = Long.parseLong(sc.next());
    long a = Long.parseLong(sc.next());
    long b = Long.parseLong(sc.next());
    if (a == 0) {
      pw.println(0);
      return;
    }
    if (b == 0) {
      pw.println(n);
      return;
    }
    long ans = 0;
    long set = n / (a + b);
    ans += set * a;
    long additional = n - (set * (a + b));
    ans += Math.min(a, additional);
    pw.println(ans);
  }
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  cin>>n;
  int p[n],a[n],b[n];
  for(int i=0;i<n;i++) cin>>p[i];
  for(int i=0;i<n;i++) a[i]=25000*(i+1),b[i]=25000*(n-i);
  for(int i=0;i<n;i++) b[p[i]-1]+=i+1;
  for(int i=0;i<n;i++){
    if(i) cout<<" ";
    cout<<a[i];
  }
  cout<<endl;
  for(int i=0;i<n;i++){
    if(i) cout<<" ";
    cout<<b[i];
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<ll>;
using VV = vector<VI>;
using VS = vector<string>;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl

VI A; // 厚さ
VI P; // パティ数

ll f(ll N, ll X){
  if(N==0){
    if(X==0){
      return 0;
    }else{
      return 1;
    }
  }
  if(X==0 || X==1) return 0;
  else if(1<X && X<=1+A[N-1]) return f(N-1, X-1);
  else if(X==2+A[N-1]) return P[N-1]+1; // ちょうど真ん中まで食べる
  else if(2+A[N-1]<X && X<=2+2*A[N-1]) return P[N-1]+1+f(N-1, X-2-A[N-1]);
  else if(X==3+2*A[N-1]) return 2*P[N-1]+1;
  else p("something wrong");
}

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

    // input
    ll N, X;
    cin >> N >> X;
    A.resize(51);
    P.resize(51);

    A[0]=1;
    P[0]=1;
    FOR(i, 1, 51){
      A[i] = 2*A[i-1]+3;
      P[i] = 2*P[i-1]+1;
    }

    ll ans = f(N, X);
    p(ans);
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define PI 3.14159265358979323846
using namespace std;
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   /// https://ideone.com/Fd5s8n

  int s,w;
  cin>>s>>w;
  if(w>=s)
    cout << "unsafe" << endl;
  else
    cout << "safe" << endl;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, n) for (int i = (n-1); i >= 0; i--)
#define rea(i, a, b) for (int i = (a); i < (b); i++)
#define reab(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(),(a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const int MOD = 1000000007;
/* END OF TEMPLATE */

int main(){
    ll N;
    cin >> N;
    vll a(N);
    vll ans(8, 0);
    ll ansq = 0;
    rep(i, N){
        cin >> a[i];
        if(a[i] < 3200){
            ans[a[i]/400] = 1;
        }else{
            ansq++;
        }
    }
    int a0 = accumulate(ALL(ans), 0);
    int a1 = a0 ? a0 : 1;
    int a2 = accumulate(ALL(ans), 0) + ansq;
    cout << a1 << " " << a2 << endl;
}

Measured memory_bytes: 256
#include<cstdio>
int main(){
	int sx,sy,tx,ty;
	while(~scanf("%d%d%d%d",&sx,&sy,&tx,&ty))
	{
		int qq,qw,qe,qr,i,k;
		qq=tx-sx;
		qw=ty-sy;
		//1 qu
		for(i=1;i<=qw;i++)
		{
			printf("U");
		}
		for(i=1;i<=qq;i++)
		{
			printf("R");
		}
		//1 hui
		for(i=1;i<=qw;i++)
		{
			printf("D");
		}
		for(i=1;i<=qq;i++)
		{
			printf("L");
		}
		//2 qu
		printf("L");
		for(i=1;i<=qw+1;i++)
		{
			printf("U");
		}
		for(i=1;i<=qq+1;i++)
		{
			printf("R");
		}
		printf("D");
		//2 hui
		printf("R");
		for(i=1;i<=qw+1;i++)
		{
			printf("D");
		}
		for(i=1;i<=qq+1;i++)
		{
			printf("L");
		}
		printf("U");
	}
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
  long long n, a, b;

  cin >> n >> a >> b;

  long long sum = a + b;
  long long time = n / sum;
  long long mod = n % sum;
  long long a_num = a * time;
  long long b_num = b * time;

  if (mod <= a) {
    a_num += mod;
  } else {
    a_num += a;
  }

  cout << a_num << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<iomanip>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define erep(i, n) for (int i = 0; i <= (int)(n); i++)

int main() {
    int n, d; cin >> n >> d;
    vector< vector<int> > x(n, vector<int>(d));
    rep (i, n) {
        rep (j, d) cin >> x[i][j];
    }

    int ans = 0;
    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            int sum = 0;
            for (int k = 0; k < d; k++) sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            int sq = sqrt(sum);
            if (sq * sq == sum) ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

    class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();

        if (a * b * c == 175)
        System.out.print("YES");

        else

        System.out.print("NO");


        scan.close();
	}

}

Measured memory_bytes: 21716
import itertools

N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for i in range(Q)]

array = list(itertools.combinations_with_replacement(range(1, M + 1), N))

maxScore = 0
for x in array:
    score = 0
    for y in abcd:
        if x[y[1] - 1] - x[y[0] - 1] == y[2]:
            score += y[3]
    maxScore = max(maxScore, score)
print(maxScore)


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

int main() {
  int h, w;
  cin >> h >> w;
  ll ans = 0;
  int ce, co;
  ce = w / 2;
  co = w / 2;
  if(w % 2 != 0) ++ce;
  if (h == 1 || w == 1) {
    cout << 1 << endl;
    return 0;
  }
  for(int i = 1; i<=h; ++i){
    if(i % 2 == 0) ans += co;
    else ans += ce;
  } 
  cout << ans << endl;
  return 0;
}

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

using namespace std;

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

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

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

void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}


void solve(){
    ll n;
    cin >> n;
    ll a, b;
    cin >> a >> b;
    if(a > b) swap(a, b);
    ll ans = inf;
    if((b-a)%2 ==0) ANS((b-a)/2);
    cout << min(a-1, n-b) + 1 + (b-a-1)/2;

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


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc107/tasks/arc101_a
N, K = read_ints()
X = read_ints()

# 右だけにK本とるとき
# 右から左に折り返してK本とるとき
# 反転させて二通りやるときの場合分けをする


def solve(X):
    ret = 10**13
    for i in range(N):
        j = i + K - 1
        if j >= N:
            continue
        if X[i] <= 0 <= X[j]:
            ret = min(ret, -2 * X[i] + X[j])  # 右スタートか左スタートかの違い
            ret = min(ret, 2 * X[j] - X[i])
    return ret


ans = solve(X)
# 右直進だけのほうがいいとき
i = bisect_left(X, 0) + K - 1
if i < N:
    ans = min(ans, X[i])
# 左直進だけのほうがいいとき
i = bisect_right(X, 0) - K
if -1 < i:
    ans = min(ans, -X[i])
# print(i, X[i])
print(ans)


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define fth(t) std::get<3>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P3 = std::tuple<int,int,int>;

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

P3 ps[60];
bool solved[60][20];
int WAs[60][20];

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

    while(true){
        int T, P, R;
        std::cin >> T >> P >> R;
        if(!T){break;}
    
        for(int i=1;i<=T;++i){
            ps[i] = std::make_tuple(0, 0, 0);
        }
        memset(solved, 0, sizeof(solved));
        memset(WAs, 0, sizeof(WAs));
    
        for(int i=0;i<R;++i){
            int tid, pid, t;
            string message;

            std::cin >> tid >> pid >> t >> message;

            if(solved[tid][pid]){continue;}
            if(message == "CORRECT"){
                ++fst(ps[tid]);
                snd(ps[tid]) += WAs[tid][pid] * 1200 + t;
                solved[tid][pid] = true;
            }else{
                ++WAs[tid][pid];
            }
        }

        for(int i=1;i<=T;++i){
            fst(ps[i]) = -fst(ps[i]);
            thd(ps[i]) = i;
        }

        sort(ps+1, ps+1+T);

        for(int i=1;i<=T;++i){
            std::cout << thd(ps[i]) << " " << (-fst(ps[i])) << " " << snd(ps[i]) << std::endl;
        }
    }
}



Measured memory_bytes: 3212
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int main(int argc, const char** argv) {
    int n;
    cin>>n;
    vector<string> results;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        results.push_back(s);
    }

    int AC=0, WA=0, TLE=0, RE=0;
    for(int i=0;i<n;i++){
        if(results[i]=="AC"){
            AC++;
        }else if(results[i]=="WA"){
            WA++;
        }else if(results[i]=="TLE"){
            TLE++;
        }else if(results[i]=="RE"){
            RE++;
        }
    }

    cout<<"AC x "<<AC<<"\n";
    cout<<"WA x "<<WA<<"\n";
    cout<<"TLE x "<<TLE<<"\n";
    cout<<"RE x "<<RE;

    return 0;
}

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

int main(){
    int S;
    int h,m,s;

    cin>> S;

    h = S / 3600;
    S %= 3600;

    m = S / 60;
    S %= 60;

    s = S;
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}


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

int x, y;
int gojo(int n, int m){
    if(!m) return n;
    else return gojo(m, n%m);
}
int main(){
    cin >> x >> y;
    if(x < y) swap(x, y);
    cout << gojo(x, y) << endl;
}

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

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  int n;
  cin >> n;

  vector<pair<int, int>> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i].first;
    a[i].second = i + 1;
  }

  sort(a.begin(), a.end(), greater<pair<int, int>>());
  vector<vector<long long>> dp(n + 1, vector<long long> (n + 1, 0));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= i; ++j) {
      dp[j + 1][i - j] = max(dp[j + 1][i - j], dp[j][i - j] + 1ll * a[i].first * (a[i].second - (j + 1)));
      dp[j][i - j + 1] = max(dp[j][i - j + 1], dp[j][i - j] + 1ll * a[i].first * (n - (i - j) - a[i].second));
    }
  }

  long long ans = 0;
  for (int i = 0; i <= n; ++i) {
    ans = max(ans, dp[i][n - i]);
  }

  cout << ans << '\n';
}



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

int main()
{
  int a=0,b=0,n;
  string A,B;

  cin>>n;
  for(int i=0;i<n;i++){
    cin>>A>>B;
    if(A==B){
      a++;
      b++;
    }
    else if(A>B)a+=3;
    else b+=3;
  }
  cout<<a<<" "<<b<<endl;
  return 0;
}
  

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
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;}

void solve(long long N, std::vector<long long> a, std::vector<long long> b){
    vvl g(N);
    vl cnt(N);
    rep(i,N-1){
        g[a[i]-1].push_back(b[i]-1);
        g[b[i]-1].push_back(a[i]-1);
        cnt[a[i]-1]++;
        cnt[b[i]-1]++;
    }

    vl color(N,-1);
    color[0]=0;
    queue<ll> q;
    q.push(0);
    while(!q.empty()){
        ll src=q.front();q.pop();
        for(ll to:g[src]){
            if(color[to]!=-1)continue;
            color[to]=1-color[src];
            q.push(to);
        }
    }

    vl cntC(2);
    rep(i,N){
        cntC[color[i]]++;
    }

    if(cntC[0]<cntC[1]){
        rep(i,N)color[i]=1-color[i];
        swap(cntC[0],cntC[1]);
    }

    ll canUse=N/3*2;
    if(N%3>=1)canUse++;
    vl nextUse(3);
    rep(i,3)nextUse[i]=i+1;
    vl colorUse={0,1,2};
    if(cntC[0]>canUse){
        colorUse={0,2,1};
    }
        
    vl ans(N);
    rep(i,N){
        if(color[i]==0){
            if(nextUse[colorUse[0]]<=N){
                ans[i]=nextUse[colorUse[0]];
                nextUse[colorUse[0]]+=3;
            }else if(nextUse[colorUse[2]]<=N){
                ans[i]=nextUse[colorUse[2]];
                nextUse[colorUse[2]]+=3;
            }else{
                ans[i]=nextUse[colorUse[1]];
                nextUse[colorUse[1]]+=3;
            }
        }else{
            if(nextUse[colorUse[1]]<=N){
                ans[i]=nextUse[colorUse[1]];
                nextUse[colorUse[1]]+=3;
            }else{
                ans[i]=nextUse[colorUse[2]];
                nextUse[colorUse[2]]+=3;
            }
        }
    }
    rep(i,N){
        if(i>0)cout<<" ";
        cout<<ans[i];
    }
    cout<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N-1);
    std::vector<long long> b(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
    }
    solve(N, std::move(a), std::move(b));
}


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

int h,w,m,a[300001],b[300001],p1,p2;
typedef pair<int,int> pi;
set<pi> st;

int main(){
	int i,j,x,y;
	cin>>h>>w>>m;
	vector<int> l,r;
	
	for(i=1;i<=m;++i){
		cin>>x>>y;
		st.insert(make_pair(x,y));
		a[x]++;
		b[y]++;
		if(a[x]>p1){
			l.clear();
			p1=a[x];
		}
		if(a[x]==p1)l.push_back(x);
		
		if(b[y]>p2){
			r.clear();
			p2=b[y];
		}
		if(b[y]==p2)r.push_back(y);
	}
	
	for(i=0;i<l.size();++i){
		for(j=0;j<r.size();++j){
			if(st.find(make_pair(l[i],r[j]))==st.end()){
				cout<<p1+p2;
				return 0;
			}
		}
	}
	
	cout<<p1+p2-1;
	return 0;
}




Measured memory_bytes: 21948
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

void primeNumber(int N, vector<bool>& prime)
{
    prime.assign(N+1, true);
    prime [0] = prime[1] = false;
    for(int i=2; i*i<=N; i++){
        if(prime[i]){
            for(int j=i; i*j<=N; j++){
                prime[i*j] = false;
            }
        }
    }
}

int main()
{
    vector<bool> isPrime;
    primeNumber(10000, isPrime);

    vector<int> prime;
    for(int i=1; i<=10000; ++i){
        if(isPrime[i])
            prime.push_back(i);
    }

    int n = prime.size();
    vector<int> ret(10001, 0);
    for(int i=0; i<n; ++i){
        int x = 0;
        for(int j=i; j<n; ++j){
            x += prime[j];
            if(x <= 10000)
                ++ ret[x];
        }
    }


    for(;;){
        int a;
        cin >> a;
        if(a == 0)
            return 0;
        cout << ret[a] << endl;
    }
}

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

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

    int N;
    cin >> N;

    vector<vector<int> > F(N, vector<int>(10));
    vector<vector<int> > P(N, vector<int>(11));

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

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

    int ans = -pow(10, 9) - 2;

    for(int bit = 1; bit < (1 << 10); bit++) {
        vector<int> S;
        for(int i = 0; i < 10; i++) {
            if(bit & (1 << i)) S.push_back(i);
        }

        int count = 0;

        for(int i = 0; i < N; i++) {
            int c = 0;
            for(int j = 0; j < S.size(); j++) {
                if(F[i][S[j]]) {
                    c++;
                }
            }
            count += P[i][c];
        }

        ans = max(ans, count);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<stack>
#include<iostream>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define MOD 1000000007
#define vec(a) vector<int>a
using namespace std;



int main()
{
#ifndef ONLINE_JUDGE
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
#endif
	ll n,m,i,j,k,l;
	cin>>n>>m;
	ll arr[n+1]={0},z=0,x=0,arr1[n+1]={0};
	for(i=0;i<m;i++)
	{
		string s;
		cin>>k>>s;
		if(arr[k]==0 && s=="WA")
			arr1[k]++;
		else if(arr[k]==0 && s=="AC")
		{
			arr[k]=1;
			x+=arr1[k];
			z++;
		}
	}
	cout<<z<<" "<<x;
}
	

Measured memory_bytes: 5188
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

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

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> z(n);
    for (int i = 0; i < n; i++) {
        cin >> z[i];
    }
    vector<ll> ans(555555);
    ll now = 0;
    for (int i = 0; i < n; i++) {
        ll zans = 0;
        for (int j = i; j < n; j++) {
            zans = zans + z[j];
            ans[now] = zans;
            now++;
        }
    }
    ll anss = 0;
    ll za = 0;
    
    for (ll i = 50; i > -1; i--) {
        ll t = 0;
        for (ll j = 0; j < 555555; j++) {
            
            if ((ans[j]&(1ull << i)) && ((anss&ans[j]) == anss))t++;
        }
        if (t >= k)anss |= (1ull << i);
    }
    cout << anss << endl;
}

Measured memory_bytes: 4608
fun main(args: Array<String>) = IO().exec {
    val n = int()
    val m = int()
    val a = IntArray(m)
    val b = IntArray(m)
    val c = LongArray(m)
    for (i in m) {
        a[i] = int()-1
        b[i] = int()-1
        c[i] = long()
    }
    val d = Array(n){LongArray(n){1L.shl(60)}}
    for (i in n) d[i][i] = 0
    for (i in m) {
        d[a[i]][b[i]] = c[i]
        d[b[i]][a[i]] = c[i]
    }
    warshallFloyd(d)
    val cnt = mutableSetOf<Int>()
    cnt.addAll(0 until m)
    for (i in n) for (j in m) if (d[i][a[j]] + c[j] == d[i][b[j]]) cnt.remove(j)
    println(cnt.size)
}

/**
 * ```d[x][y] = cost or INF, d[i][i] = 0```
 */
fun warshallFloyd(d: Array<LongArray>) {
    val n = d.size
    for (k in n) for (i in n) for (j in n)
        d[i][j] = Math.min(d[i][j], d[i][k] + d[k][j])
}

// region template
operator fun Int.iterator() = 0.until(this).iterator()

class IO {
    val printable = 33..126
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0
    val out = java.io.PrintWriter(System.out)
    fun hasNextByte(): Boolean = if (ptr < buflen) true else {
        ptr = 0
        buflen = System.`in`.read(buffer)
        buflen > 0
    }

    fun readByte(): Byte = if (hasNextByte()) buffer[ptr++] else -1
    fun hasNext(): Boolean {
        while (hasNextByte() && buffer[ptr] !in printable) ptr++
        return hasNextByte()
    }

    fun string(): String {
        if (!hasNext()) throw java.util.NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (b in printable) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }

    fun long(): Long {
        if (!hasNext()) throw java.util.NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
        if (b !in '0'.toByte()..'9'.toByte()) {
            throw NumberFormatException()
        }
        while (true) {
            if (b in '0'.toByte()..'9'.toByte()) {
                n *= 10
                n += b - '0'.toByte()
            } else if (b == (-1).toByte() || b !in printable) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun int(): Int {
        val nl = long()
        if (nl !in Integer.MIN_VALUE..Integer.MAX_VALUE) throw NumberFormatException()
        return nl.toInt()
    }

    fun double(): Double = string().toDouble()
    fun print(obj: Any) = out.print(obj)
    fun print(i: Int) = out.print(i)
    fun print(l: Long) = out.print(l)
    fun println(obj: Any) = out.println(obj)
    fun println(i: Int) = out.println(i)
    fun println(l: Long) = out.println(l)
    inline fun exec(block: IO.() -> Unit) {
        block()
        out.flush()
    }
}
// endregion

Measured memory_bytes: 33964