akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCorder
{
	public class Program
	{
		static List<int>[] blueTargets;
		static int[] pairs;
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			var reds = new Tuple<int, int>[n];
			var blues = new Tuple<int, int>[n];
			for (int i = 0; i < n; i++) {
				var ab = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
				reds[i] = new Tuple<int, int>(ab[0], ab[1]);
			}

			for (int i = 0; i < n; i++) {
				var ab = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
				blues[i] = new Tuple<int, int>(ab[0], ab[1]);
			}

			blueTargets = new List<int>[n];
			for (int r = 0; r < n; r++) {
				blueTargets[r] = new List<int>();
				for (int b = 0; b < n; b++) {
					if (reds[r].Item1 < blues[b].Item1 && reds[r].Item2 < blues[b].Item2) {
						blueTargets[r].Add(b);
					}
				}
			}

			
			pairs = new int[n];
			for (int b = 0; b < n; b++) {
				pairs[b] = -1;
			}

			var redQ = new Queue<int>();
			for (int r = 0; r < n; r++) {
				if (blueTargets[r].Count == 0) {
					continue;
				}

				foreach (int b in blueTargets[r]) {
					bool[] check = new bool[n];
					bool ret = dfs(r, b, check);
					if (ret) {
						break;
					}
				}
			}

			int ans = pairs.Where(x => x != -1).Count();
			Console.WriteLine(ans);
		}

		static bool dfs(int nextR, int nextB, bool[] check)
		{
			if (pairs[nextB] == -1) {
				pairs[nextB] = nextR;
				return true;
			}

			check[nextB] = true;
			int oldB = nextB;
			int oldR = nextR;
			nextR = pairs[nextB];
			foreach (int b in blueTargets[nextR]) {
				if (check[b]) {
					continue;
				}

				bool ret = dfs(nextR, b, check);
				if (ret) {
					pairs[oldB] = oldR;
					return true;
				}
			}

			return false;
		}
	}
}


Measured memory_bytes: 13652
import java.util.*;
import java.io.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for(int i = 0; i<n; i++)
            a[i] = sc.nextLong();
        long[][] dp = new long[n][n];
        for(int l = n-1; l>=0; l--) {
            for(int r = l; r<n; r++) {
                if(l==r) continue;
                dp[l][r] = Long.MAX_VALUE;
                long sum = 0;
                for(int i = l; i<=r; i++)
                    sum+=a[i];
                for(int k = l; k<r; k++)
                    dp[l][r] = Math.min(dp[l][r], dp[l][k]+dp[k+1][r]+sum);
            }
        }
        System.out.println(dp[0][n-1]);
    }
}

Measured memory_bytes: 26324
import java.util.*;

public class Main {

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

        int[] h = new int[N];
        for (int i = 0; i < N; i++) h[i] = scanner.nextInt();

        int result = solve(h, N, K);
        System.out.println(result);

        //test();
    }

    private static int solve(int[] h, int N, int K) {
        int bufSize = Math.min(K, N);

        int[] cost = new int[bufSize];
        Arrays.fill(cost, Integer.MAX_VALUE);
        cost[0] = 0;

        for (int i = 0; i <= N-2; i++) {
            int ahead = Math.min(bufSize, N - i - 1);
            int startCost = cost[0];
            for (int k = 0; k < ahead; k++) {
                int candidate = startCost + Math.abs(h[i + k + 1] - h[i]);
                cost[k] = (k + 1 < bufSize) ? Math.min(cost[k+1], candidate): candidate;
            }
        }

        return cost[0];
    }

    private static void test() {
        testCase(new int[] { 10, 30, 40, 50, 20}, 3, 30);
        testCase(new int[] { 10, 20, 10 }, 1,20);
        testCase(new int[] { 10, 10 }, 100,0);
        testCase(new int[] { 40, 10, 20, 70, 80, 10, 20, 70, 80, 60 }, 4,40);
        System.out.println("DONE");
    }

    private static void testCase(int[] h, int K, int expected) {
        int result = solve(h, h.length, K);
        if (result != expected) {
            System.out.println("FAILED " + Arrays.toString(h) + " K=" + K + ", was " + result + " expected " + expected);
        }
    }
}


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

int main(){
  
  int N;
  scanf("%d\n",&N);
  
  int ans;
  if( N%1000 == 0){
    ans = 0;
  }else{
    ans = 1000 - N%1000;
  }
  printf("%d\n", ans );
  return 0;
  
}

Measured memory_bytes: 3824
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
import java.util.Stack;

public class Main {
	
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
	

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
   
  // static Scanner sc = new Scanner(System.in);
  
    private final static int mod = (int) (1e9 + 7);
    private final static int N = (int) (1e6);
	public static void main(String[] args) {
	   
	 FastReader sc = new FastReader();
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] h = new int[n];
		for(int i=0;i<n;++i) h[i] = sc.nextInt();
		int[] dp = new int[n];
		dp[0] = 0;
		
		for(int i=1;i<n;++i) {
			int best = Integer.MAX_VALUE;
			for(int j=i-1;j>=Math.max(0,i-k);--j)
			    best = Math.min(best,dp[j] + Math.abs(h[j]-h[i]));
				
				dp[i] = best;
		}
		out.print(dp[n-1]);
	 out.close();
    
	}

	private static long pow(long a, int b) {
		if(b == 0) return 1;
		long temp = pow(a,b/2);
		temp = (temp*temp)%mod;
		if((b&1) == 1) temp = (a*temp)%mod;
		return temp;
	}
}

Measured memory_bytes: 33400
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define pb(a) push_back(a)

typedef long long ll;
using namespace std;

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

//const int dy[] = { 0, 0, 1, -1 };
//const int dx[] = { 1, -1, 0, 0 };
const int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
ll gcd(ll a, ll b);
ll lcm(ll x, ll y);

vector<ll> a;

int main()
{
	int s;
	cin >> s;

	for(int i=0;i<3;i++){
		int dig = s % 10;
		if (dig == 7) {
			cout << "Yes" << endl;
			return 0;
		}
		s = s / 10;
	}
	
	cout << "No" << endl;
	
	return 0;
}


Measured memory_bytes: 3580
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    const [S, W] = nextIntArray()
    if(S <= W) console.log('unsafe')
    else console.log('safe')
}
Main()


Measured memory_bytes: 29556
// I - Coins
#include <bits/stdc++.h>
using namespace std;
using dl = double;

dl dp[2999+2];

int main(){
	int N; scanf("%d",&N);
	int C = (N+1)/2;
	dp[1] = 1.;
	for(int lv=1; lv<=N; lv++){
		dl p; scanf("%lf",&p);
		dl q = 1.-p;
		int e = max(1, lv-C+2);
		for(int i=lv+1; i>=e; i--) dp[i] = q*dp[i] + p*dp[i-1];
	}
	dl a = 0; for(int i=N+1; i>C; i--) a += dp[i];
	printf("%.10g\n",a);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <cfloat>
#include <map>
using namespace std;
int main(){

	string a,b;
	
	while(cin>>a>>b,a!="0"||b!="0"){
		int h=0,l=0;
	for(int i=0;i<4;i++){
		for(int j=0;j<4;j++){
			if(a[i]==b[j]){
				if(i==j)
					h++;
				else
					l++;
			}
		}
	}
		cout<<h<<" "<<l<<endl;
	}
}

Measured memory_bytes: 1184
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		long l =sc.nextInt();

		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i=0;i<n;i++) {
			a[i]=sc.nextInt();
		}
		
		long[] leftSum = new long[n];
		leftSum[0]=a[0]*2;
		long[] rightSum = new long[n];
		rightSum[n-1]=(l-a[n-1])*2;
		for (int i=1;i<n;i++) {
			leftSum[i]=leftSum[i-1]+a[i]*2;
		}
		for (int i=n-2;i>=0;i--) {
			rightSum[i]=rightSum[i+1]+(l-a[i])*2;
		}
		
		
		long ans = 0;
		
		for (int i=0;i<n;i++) {
			long tmp1=0;
			long tmp2=0;
			long tmp3=0;
			int base = 0;
			//left once more
			if (i>=1) {
				base = Math.min(i-1, n-1-i);
				tmp1 += (i+1==n ? 0 : rightSum[i+1])-(i+base+1==n ? 0 : rightSum[i+base+1]);
				tmp1 += leftSum[i-1]-(i-base-2==-1 ? 0 : leftSum[i-base-2]);
				tmp1 += l-a[i];
			}
			// same number
				base = Math.min(i, n-1-i);
				tmp2 += (i+1==n ? 0 :rightSum[i+1])-(i+base+1==n ? 0 : rightSum[i+base+1]);
				tmp2 += (i-1 == -1 ? 0 :leftSum[i-1])-(i-base-1==-1 ? 0 : leftSum[i-base-1]);
				tmp2 += Math.max(a[i],l-a[i]);
			// right once more
			if (i<=n-2) {
				base = Math.min(i, n-2-i);
				tmp3 += rightSum[i+1]-(i+base+2==n ? 0 : rightSum[i+base+2]);
				tmp3 += (i-1 == -1 ? 0 : leftSum[i-1])-(i-base-1==-1 ? 0 : leftSum[i-base-1]);
				tmp3 += a[i];
			}
			
			ans = Math.max(Math.max(ans, tmp1), Math.max(tmp2, tmp3));
/*			
			if(ans==tmp1) {
				System.out.println(i+" tmp1 "+ans);
			}
			if(ans==tmp2) {
				System.out.println(i+" tmp2 "+ans);
			}
			if(ans==tmp3) {
				System.out.println(i+" tmp3 "+ans);
			}
*/
		}
		System.out.println(ans);
		
		
	}
}


Measured memory_bytes: 66332
#include<bits/stdc++.h>
  using namespace std;
int n;
inline void into(){
  scanf("%d",&n);
}
inline void work(){
}
inline void outo(){
  if (n<=999) printf("ABC\n");
  else printf("ABD\n");
}
int main(){
  into();
  work();
  outo();
  return 0;
}

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

using LL = long long;

const int N = 1e5;
vector<int> adj[N];
int other[N];
pair<int, int> edges[N];
int col[N];

void dfs(int u, int p, int c) {
	int cur = 1;
	for (int i: adj[u]) {
		int v = other[i] ^ u;
		if (v == p) continue;
		if (cur == c) cur++;
		col[i] = cur++;
		dfs(v, u, col[i]);
	}
}

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
	ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

	int n; cin >> n;
	for (int i = 0; i < n - 1; i++) {
	    int u, v; cin >> u >> v; u--, v--;
	    adj[u].push_back(i);
	    adj[v].push_back(i);
	    edges[i] = {u, v};
	    other[i] = u ^ v;
	}

	dfs(0, 0, 0);
	int used = 0;
	for (int i = 0; i < n - 1; i++) {
		used = max(used, col[i]);
	}
	cout << used << endl;
	for (int i = 0; i < n - 1; i++) {
		cout << col[i] << '\n';
	}

	return 0;
}


Measured memory_bytes: 9984
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

int n, u, k, v, d[110], f[110], tim=0;
bool vis[110];
vector<int> adj[110];

void dfs (int p)
{
    tim++;
    vis[p]=true;
    d[p]=tim;
    for (auto u : adj[p])
    {
        if (!vis[u]) dfs(u);
    }
    tim++;
    f[p]=tim;
}

int main()
{
    memset(vis, false, sizeof(vis));
    cin>>n;
    for (int i=0; i<n; i++)
    {
        cin>>u>>k;
        for (int j=0; j<k; j++)
        {
            cin>>v;
            adj[u].push_back(v);
        }
    }
    for (int i=1; i<=n; i++)
    {
        if (!vis[i]) dfs(i);
    }
    for (int i=1; i<=n; i++)
    {
        cout<<i<<' '<<d[i]<<' '<<f[i]<<'\n';
    }
    return 0;
}



Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
//#define int long long int
#define L_T_S_K ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);  

const int mod = 1e9 + 7 ;
const int N = 1e3 + 9;
int n , arr[21 + 1][21 + 1];
int dp[(1LL << 21)][25];
int add(int x , int y){
	return (x % mod + y % mod) % mod;
}
int solve(int mask , int id){
	//cout << mask << " " << id << endl;
	if(id == n and mask == ((1LL << n) - 1)){
		return 1;
	}
	if(id >= n) return 0;
	if(dp[mask][id] != -1) return dp[mask][id];
	int ans = 0;
	for(int i = 0 ; i < n ; i++){
		if(arr[id][i]){
			if(mask&(1 << i)) continue;
			ans = add(ans , solve(mask|(1 << i) , id + 1));
		}
	}
	dp[mask][id] = ans;
	return ans;
}
int32_t main(){
 L_T_S_K;
 int t = 1;
// cin >> t;
 memset(dp , -1 , sizeof dp);
 while(t--){
 	cin >> n;
 	for(int i = 0 ; i < n ; ++i){
 		for(int j = 0 ; j < n ; ++j){
 			cin >> arr[i][j];
 		}
 	}
 	cout << solve(0 , 0);
 }
  return 0;		
}

Measured memory_bytes: 205056
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int n;
    cin >> n;
    int l[n];
    for(int i = 0;i<n;i++) cin >> l[i];
    sort(l,l+n);
    long ans = 0;
    for(int i = 0;i<n-1;i++){
        for(int j = i+1;j<n;j++){
            auto itr1 = lower_bound(l,l+n,l[i]+l[j]);
            auto itr2 = lower_bound(l,l+n,l[j]-l[i]+1);
            ans += (itr1-itr2);
            if(l[i]>(l[j]-l[i])) ans--;
            ans--;
        }
    }
    cout << ans/3 << endl;
}

Measured memory_bytes: 256
#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;
int main(){	
	int n;
	while(cin>>n){
	      if(n==0) return 0;
	      vector<int> id;
	      vector<long long> sale(4001,-1);
	      int x,y,z;
	      for(int i=0;i<n;i++){
		cin>>x>>y>>z;
               if(sale[x]==-1){
                  sale[x]=0;
		  id.push_back(x);}
	       sale[x]+=(long long )y*z;
	       }
               bool na = true;
	       for(int i=0;i<(int)id.size();i++){
                     if(sale[id[i]] >= 1000000){                          
				cout<<id[i]<<endl;
				na = false;
		     }
		}
		if(na) cout<<"NA"<<endl;
	}

}

Measured memory_bytes: 1256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    int n, m, *ccnt, cnt, a, b;

    scanf("%d %d", &n, &m);
    ccnt = (int *)malloc(sizeof(int) * n);

    memset(ccnt, 0, m);

    for(cnt = 0; cnt < m; cnt++)
    {
        scanf("%d %d", &a, &b);
        ccnt[a - 1] +=1;
        ccnt[b - 1] +=1;
    }

    for(cnt = 0; cnt < n;cnt++)
    {
        printf("%d\n", ccnt[cnt]);
    }

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
const long long MOD = 1000000007;
const int INF = INT_MAX / 2;
const long double PI = 3.141592653289793;
using namespace std;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
#define lld long double
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> vp;
typedef vector<tuple<ll, ll, ll>> vt;
//vector<vector<ll>> vv(n, vector<ll>(n));

int main()
{
	vp v;
	ll n;
	cin >> n;
	REP(i,n)
	{
		ll a, b;
		cin >> a >> b;
		v.emplace_back(a, b);
	}
	sort(ALL(v));
	cout << v[n - 1].first + v[n - 1].second << endl;
}

Measured memory_bytes: 2548
#include<iostream>
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a+b>c+d) cout << "Left" << endl;
	else if(a+b==c+d) cout << "Balanced" << endl;
	else cout << "Right" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if ((A+B)<(C+D)){
      cout << "Right" << endl;
  }
  else if ((A+B)>(C+D)){
      cout << "Left" << endl;
  }
  else{
      cout << "Balanced" << endl;
  }
}

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

ll countWaysUtil(ll n,ll m) 
{ 
    ll res[n];
    ll j=0;
    res[0] = 1; res[1] = 1;
    if(j<m && 1==a[j])
     {res[1]=0;
     j=j+1;
     }
    for (ll i=2; i<n; i++) 
    {if(j<m && i==a[j])
           {res[i]=0;
           j=j+1;
           }
        else
           res[i] = (res[i-1]+res[i-2])%1000000007; 
    } 
    return res[n-1];
} 
  

ll countways(ll s,ll m) 
{ 
    return countWaysUtil(s+1,m); 
} 
  
 
int main () 
{ll n,m;
cin>>n>>m;
ll x;
for(ll i=0;i<m;i++)
  {cin>>x;
   a.push_back(x);
  }
cout<<countways(n,m);
} 

Measured memory_bytes: 1908
module M = Map.Make(struct type t = int let compare = compare end)
;;
Scanf.scanf "%d %d\n" (fun n m ->
  let r = Array.make m (0,0) in
  let r2 = Array.make (n+1) [] in
  for i=0 to m-1 do
     Scanf.scanf "%d %d\n" (fun p1 y1->
       r2.(p1) <- y1::r2.(p1);
       r.(i) <- (p1,y1)
    )
  done;
  let r3 = Array.make (n+1) M.empty in
  for i=0 to n do
    let ls = List.sort (fun x y->x-y) r2.(i) in
    let (_,ls)=List.fold_left(fun (i,l) x -> (i+1,M.add x i l)) (1,M.empty) ls in
    r3.(i) <- ls
  done;

  Array.iter (fun (p,y) ->
    let n = M.find y r3.(p) in
    Printf.printf "%06d%06d\n" p n
  ) r
)


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

using namespace std;

const auto INF = 1e9;
const auto NMAX = 100000 + 5;
int h[NMAX];
int dp[NMAX];

int main() {
    int N, K;
    cin >> N >> K;
    for (int i = 0; i < N; i++) cin >> h[i];

    dp[0] = 0;
    for (int i = 1; i < N; ++i) dp[i] = INF;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j <= i + K and j < N; ++j) {
            dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]));
        }
    }
    cout << dp[N - 1] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<string>

using namespace std;

int main(){
    int n;
    int p1=0,p2=0;
    string str1,str2;
    cin>>n;
    
    for(int i=0; i<n; i++){
        cin>>str1;
        cin>>str2;
        
        if(str1>str2)p1+=3;
        else if(str2>str1)p2+=3;
        else{
            p1+=1;
            p2+=1;
        }
    }
    
    printf("%d %d\n",p1,p2);
    return 0;

}


Measured memory_bytes: 3248
a,b,c = map(int,input().split())
if a%2==1 or b%2==1 or c%2==1:
  print(0)
elif a == b == c:
  print(-1)
else:
  ans = 0
  while a%2==b%2==c%2==0:
    a,b,c = (b+c)//2,(c+a)//2,(a+b)//2
    ans += 1
  print(ans)

Measured memory_bytes: 38256
#include <cstdio>

struct M
{
  int value[9];
  int operator()(int i, int j)
  {
    return value[(i % 3) * 3 + (j % 3)];
  }
};

int main()
{
  M m;
  for (int i = 0; i < 9; ++i)
  {
    scanf("%d", m.value + i);
  }

  for (int i = 0; i < 3; ++i)
  {
    for (int j = 0; j < 3; ++j)
    {
      if
      (
        m(i, j) - m(i + 1, j) != m(i, j + 1) - m(i + 1, j + 1) ||
        m(i, j) - m(i, j + 1) != m(i + 1, j) - m(i + 1, j + 1)
      )
      {
        puts("No");
        return 0;
      }
    }
  }
  puts("Yes");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main(){
	int n;
	while(cin >> n, n){
		int res = 0;
		for(int i=1;i<=n;i++){
			for(int j=i+1;j<=n;j++){
				int sum = (i+j)*(j-i+1)/2;
				if(sum == n){
					res++;
				}
			}
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 1164
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int n;
    cin >> n;
    vi a(n);
    rep(i,n){
        int t;
        cin >> t;
        t--;
        a[t] = i;
    }
    rep(i,n)cout << a[i]+1 << " \n"[i == n-1];
}


Measured memory_bytes: 1536
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const long long INF=1LL << 60;
long long a,b;
long long dp[100200][110];
long long w[110],v[110];

int main() {
   int a,b,c;
   cin>>a>>b>>c;
   cout<<(a+b)*c/2<<endl;
}


Measured memory_bytes: 256
n = int(input())
# print('n',n)

# 素数と個数を求める
def factorize(n):
    res = []
    for i in range(2,n):
        if i*i > n: break
        if n%i: continue
        res += [[i,0]]
        while n%i == 0:
            n //= i
            res[-1][1] += 1
    if n != 1: res += [[n,1]]
    return res

P = factorize(n)
# print(P)

ans = 0
for pc in P:
    for c in range(1, pc[1]+1):
        pp = pc[0]**c
        if n%pp: continue
        n //= pp
        ans += 1

print(ans)


Measured memory_bytes: 9212
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int n;
P a[202020];

int main(){
  cin >> n;
  rep(i, n){
    a[i].second = i + 1;
    cin >> a[i].first;
  }
  sort(a, a + n);
  rep(i, n){
    cout << a[i].second << ((i == n - 1) ? "\n" : " ");
  }
  return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
#include <bitset>
#include <cassert>
using namespace std;

typedef long long ll;



int main() {
	int d; cin >> d;
	cout << "Christmas";
	for (int i = 0; i < 25 - d; i++) cout << " Eve"; cout << endl;
	return 0;
}


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> H(N);
    for(int i = 0; i < N; i++) {
        cin >> H.at(i);
    }

    vector<vector<int>> ways(N);
    int from, to;
    for(int i = 0; i < M; i++) {
        cin >> from >> to;
        from--;
        to--;
        ways.at(from).push_back(to);
        ways.at(to).push_back(from);
    }

    int ans = 0;
    for(int i = 0; i < N; i++) {
        bool good = true;
        for(int other : ways.at(i)) {
            // cout << "i=" << i << " other=" << other << endl;
            if(H.at(i) <= H.at(other)) {
                good = false;
                break;
            }
        }

        // cout << "i:" << i << " good:" << good << endl;
        if(good) {
            ans++;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8804
// ABC088C.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
using namespace std;
int main()
{
	int c[10];
	for (int i = 1; i <= 9; i++)cin >> c[i];
	int res[13] = {};
		res[1] = c[2] - c[1];
		res[2] = c[5] - c[4];
		res[3] = c[8] - c[7];

		res[4] = c[3] - c[2];
		res[5] = c[6] - c[5];
		res[6] = c[9] - c[8];

		res[7] = c[1] - c[4];
		res[8] = c[2] - c[5];
		res[9] = c[3] - c[6];

		res[10] = c[4] - c[7];
		res[11] = c[5] - c[8];
		res[12] = c[6] - c[9];
		
		//for (int i = 1; i <= 12; i++)cout << res[i];
		if (((res[1] == res[2]) && (res[1] == res[3])) 
			&&	((res[4] == res[5]) && (res[4] == res[6])) 
			&&	((res[7] == res[8]) && (res[7] == res[9])) 
			&&	((res[10] == res[11]) && (res[10] == res[12]))
			)cout << "Yes" << endl;
		else cout << "No" << endl;
		return 0;
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    COMinit();
    int n, k;
    cin >> n >> k;
    rep(i, k){
        int ii = i + 1;
        cout << COM(k - 1, ii - 1) * COM(n - k + 1, ii) % MOD << endl;
    }


}

Measured memory_bytes: 12160
sx, sy, tx, ty = map(int, input().split())
ans = ""
#一回目
ans += "R"*(tx-sx)
ans += "U"*(ty-sy)
ans += "L"*(tx-sx)
ans += "D"*(ty-sy)
#二回目
ans += "D"
ans += "R"*(tx-sx+1)
ans += "U"*(ty-sy+1)
ans += "L"
ans += "U"
ans += "L"*(tx-sx+1)
ans += "D"*(ty-sy+1)
ans+="R"
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int i = 1;
		
		do {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + i);
			}else{
				do{
					if (x % 10 == 3) {
						System.out.print(" " + i);
						break;
					}else{
						x /= 10;
					}
				}while(x != 0);
			}
		}while(++i <= n);
		System.out.println();	
	}
}

Measured memory_bytes: 28484
package main

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

func exec(stdin *Stdin, stdout *Stdout) {
	h := stdin.ReadInt()
	w := stdin.ReadInt()
	k := stdin.ReadInt()
	s := make([][]int, h)
	for i := 0; i < h; i++ {
		line := stdin.Read()
		s[i] = make([]int, w)
		for j := 0; j < w; j++ {
			if line[j] == '0' {
				s[i][j] = 0
			} else {
				s[i][j] = 1
			}
		}
	}

	ans := h * w
	for _, crack := range Combinations(h-1, -1) {
		crack = append(crack, -1)

		x := 0
		cur := make([]int, len(crack)+1)
		for i := 0; i < h; i++ {
			cur[x] += s[i][0]
			if crack[x] == i {
				x++
			}
		}

		ng := false
		count := 0
		for j := 1; j < w; j++ {
			nxt := make([]int, len(crack)+1)
			for i := 0; i < len(cur); i++ {
				if k < cur[i] {
					ng = true
					break
				}
				nxt[i] = cur[i]
			}

			if ng {
				break
			}

			x = 0
			cracking := false
			for i := 0; i < h; i++ {
				nxt[x] += s[i][j]
				if k < nxt[x] {
					cracking = true
				}
				if crack[x] == i {
					x++
				}
			}

			if cracking {
				count++
				for i := 0; i < len(cur); i++ {
					nxt[i] -= cur[i]
				}
			}
			cur = nxt
		}

		if !ng {
			ans = Min(ans, count+len(crack)-1)
		}
	}

	stdout.Println(ans)
}

func Combinations(n int, r int) [][]int {
	ans := [][]int{}
	for x := uint(0); x < (uint(1) << uint(n)); x++ {
		idxs := []int{}
		for i := uint(0); i < uint(n); i++ {
			if x&(uint(1)<<i) != 0 {
				idxs = append(idxs, int(i))
			}
		}
		if r < 0 || len(idxs) == r {
			ans = append(ans, idxs)
		}
	}
	return ans
}

func Min(a int, b ...int) int {
	for _, v := range b {
		if v < a {
			a = v
		}
	}
	return a
}

func main() {
	stdout := NewStdout()
	defer stdout.Flush()
	exec(NewStdin(bufio.ScanWords), stdout)
}

type Stdin struct {
	stdin *bufio.Scanner
}

func NewStdin(split bufio.SplitFunc) *Stdin {
	s := Stdin{bufio.NewScanner(os.Stdin)}
	s.stdin.Split(split)
	s.stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), int(math.MaxInt32))
	return &s
}

func (s *Stdin) Read() string {
	s.stdin.Scan()
	return s.stdin.Text()
}

func (s *Stdin) ReadInt() int {
	n, _ := strconv.Atoi(s.Read())
	return n
}

func (s *Stdin) ReadFloat64() float64 {
	n, _ := strconv.ParseFloat(s.Read(), 64)
	return n
}

type Stdout struct {
	stdout *bufio.Writer
}

func NewStdout() *Stdout {
	return &Stdout{bufio.NewWriter(os.Stdout)}
}

func (s *Stdout) Flush() {
	s.stdout.Flush()
}

func (s *Stdout) Println(a ...interface{}) {
	fmt.Fprintln(s.stdout, a...)
}


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

string s;
bool ok(int from, int to) {
    from --; to --;
    bool ret = true;
    int l = to - from + 1;
    for (int i = 0; i < l; i++) {
        if (s[from + i] != s[to - i]) {
            ret = false;
            break;
        }
    }
    return ret;
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> s;
    int l = s.length();
    auto ans = ok(1, l) && ok(1, (l - 1) / 2) && ok((l + 3) / 2, l);
    cout << (ans ? "Yes" : "No" ) << endl;
    return 0;
}





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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

template<typename FI,typename Compare>
pair<FI,FI> search_continuous(FI first,FI last,Compare comp){
	FI top = find_if(first,last,comp);
	if(top==last){
		return make_pair(last,last);
	}
	FI end = find_if_not(top,last,comp);
	return make_pair(top,end);
}

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

	string S=in<string>();
	int N = S.size();
	vector<int> V(N,0),C(N,0);
	REP(i,N){
		V[i] = S[i]=='R' ? 0 :1;
	}
	int sw = 0;
	auto start = V.begin(),end = V.end();
	while(true){
		auto resR = search_continuous(start,end,[&](int v){return v==0;});
		if(resR.first==V.end()) break;
		auto resL = search_continuous(resR.first,end,[&](int v){return v==1;});
		int dist = distance(resR.first,resL.second);
		int distR = distance(resR.first,resR.second);
		int distL = distance(resL.first,resL.second);
		int index = distance(V.begin(),resR.first);
		int even = 0,odd = 0;
		for(int i=index;i<index+dist;i++){
			if(abs(i-(index+distR-1))%2) odd++;
			else even++;
		}
		//if(index%2 == (index+distR)%2) swap(even,odd);
		C[index+distR-1] = even;
		C[index+distR] = odd;
		start = resL.second;
	}

	PRINTALL(C);
	return 0;
}


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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/f.in", "r", stdin);
//  freopen("../IO/f.out", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}


constexpr int N = 200000 + 55;
vector<int> g[N];
int a[N], ans[N];
vector<int> logsize(1, 0);
struct LIS_rollback {
  int size = 0;
  vector<int> st;
  vector<pair<int, int>> res;
  vector<pair<int, int>> log;
  vector<pair<int, int>> log1;
  void add(int el) {
    st.push_back(el);
    auto it = lower_bound(res.begin(), res.end(), pair<int, int>{el, 0});
    if (it == res.end()) {
      res.emplace_back();
      it = res.end() - 1;

      log.emplace_back(0, -1);
      log1.emplace_back(0, -1);
    } else {
      log.push_back({1, it - res.begin()});
      log1.push_back(*it);
    }
    *it = {el, st.size() - 1};

    size = res.size();
    logsize.push_back(log.size());
  }
  void rollback() {
    st.pop_back();
    logsize.pop_back();
    while (log.size() != logsize.back()) {
      if (log.back().first == 0) {
        res.pop_back();
      } else {
        assert(log.back().second != -1);
        res[log.back().second] = log1.back();
      }
      size = res.size();
      log.pop_back();
      log1.pop_back();
    }
  }
  int get() {
    return size;
  }
} LIS;

//int lis(const vector<int>& S) {
//  if (S.empty()) return {};
//  typedef pair<int, int> p;
//  vector<p> res;
//  for (int i = 0; i < S.size(); ++i) {
//    auto it = lower_bound(res.begin(), res.end(), p{S[i], 0});
//    if (it == res.end()) res.emplace_back(), it = res.end()-1;
//    *it = {S[i], i};
//  }
//  return res.size();
//}

void dfs(int u, int p) {
  LIS.add(a[u]);
  ans[u] = LIS.get();
  for (int v : g[u]) if (v != p) {
    dfs(v, u);
  }
  LIS.rollback();
}

void solve(std::istream &in, std::ostream &out) {
  int n; in >> n;
  for (int i = 1; i <= n; ++i) in >> a[i];
  for (int i = 1, a, b; i < n; ++i) {
    in >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(1, 0);
  for (int i = 1; i <= n; ++i) {
    out << ans[i] << '\n';
  }
}


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

using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }


const ll MOD = 1000000000 + 7;
const int INF = 1e9 + 1000;
class Solver {
  public:
    bool solve() {
        int N; cin >> N;
        vector<int> T(N), A(N); cin >> T >> A;
        vector<int> M(N, INF), R(N, INF);
        bool fail = false;

        if(N == 1 and T[0] != A[0]) fail = true; 
        R[0] = T[0];
        R[N - 1] = A[N - 1];

        auto run = [&](const vector<int> &a) {
            rep(i, N - 1) {
                if(a[i + 1] == a[i]) {
                    set_min(M[i + 1], a[i + 1]);
                } else {
                    fail |= (M[i + 1] < INF and M[i + 1] < a[i + 1]);
                    fail |= (R[i + 1] < INF and R[i + 1] != a[i + 1]);
                    R[i + 1] = a[i + 1];
                }
            }
        };

        run(T);        
        reverse(all(A));
        reverse(all(M));
        reverse(all(R));
        run(A);
        reverse(all(M));
        reverse(all(R));
        run(T);
        
        ll ans = 1;
        rep(i, N) if(R[i] == INF) {
            assert(M[i] < INF);
            ans = (ans * M[i]) % MOD;
        }
        
        cout << (fail ? 0 : ans) << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 1792
#131_E
n,k=map(int,input().split())
edges=[[1,i] for i in range(2,n+1)]
cnt=(n-1)*(n-2)//2
ans=n-1
if cnt<k:
    print(-1)
else:
    for i in range(2,n):
        for j in range(i+1,n+1):
            if cnt>k:
                cnt-=1
                ans+=1
                edges.append([i,j])
            else:
                break
    print(ans)
    for edge in edges:
        print(*edge)

Measured memory_bytes: 4120
N = int(input())
A_list = []
for i in range(N):
    A = int(input())
    A_list.append(A)
# print(A_list)

ans = 0
tmp = 0
for i in range(len(A_list)):
    if A_list[i] != 0:
        if i == len(A_list)-1:
            tmp += A_list[i]
            ans += int(tmp/2)
        else:
            tmp += A_list[i]
    else:
        ans += int(tmp/2)
        tmp = 0

print(ans)

Measured memory_bytes: 12908
#include <bits/stdc++.h>
#define fst ios_base::sync_with_stdio(0); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI acos(-1.0)
#define rd freopen("ip.txt","r",stdin)
#define wr freopen("op.txt", "w", stdout)
#define wis(x) cerr << #x << " is " << x << endl;
#define mem(array,int) memset(array,int,sizeof(array))
#define ll long long int
#define nl cout<<endl;
#define mx 100009
#define MOD 1000000007
using namespace std;



int main(){

   // rd;

    double N,D;

    cin>>N>>D;

    int carry = ( D*2 ) + 1;

    double  hold = N / carry;

    int buffer = ceil(hold);

    cout<<buffer<<endl;

    return  0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<numeric>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
//#define MOD 1000000007
#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    string s; cin >> s;
    int n = s.size();
    int sum = 0;
    rep(i,n){
        sum += s[i]-'0';
    }
    cout << (sum%9 == 0?"Yes":"No") << endl;
}



Measured memory_bytes: 3708
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> cnt(3);
    for(int i=0; i<3; ++i)
        cin >> cnt[i];
    vector<pair<int, int> > index(n);
    for(int i=0; i<n; ++i){
        char x, y;
        cin >> x >> y;
        index[i].first = x - 'A';
        index[i].second = y - 'A';
    }

    vector<int> ans(n);
    for(int i=0; i<n; ++i){
        if(cnt[index[i].first] > 0){
            -- cnt[index[i].first];
            ++ cnt[index[i].second];
            if(!(i < n - 1 && cnt[index[i+1].first] == 0 && cnt[index[i+1].second] == 0)){
                ans[i] = index[i].second;
                continue;
            }
            ++ cnt[index[i].first];
            -- cnt[index[i].second];
        }
        if(cnt[index[i].second] == 0){
            cout << "No" << endl;
            return 0;
        }
        ++ cnt[index[i].first];
        -- cnt[index[i].second];
        ans[i] = index[i].first;
    }

    cout << "Yes" << endl;
    for(int i=0; i<n; ++i){
        char c = ans[i] + 'A';
        cout << c << endl;
    }

    return 0;
}


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

void solve() 
{
    ll n,sum=0;cin>>n;
    rep(i,1,n+1)if(i%3&&i%5)sum+=i;
    cout<<sum<<endl;
}

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

Measured memory_bytes: 3648
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>
#include <cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;

inline bool check(ll x, ll y, ll xMax, ll yMax) { return x >= 0 && y >= 0 && xMax > x && yMax > y; }
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string tostring(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }
template<class T> inline T mypow(T x, ll n) { T res = 1; while (n > 0) { if (n & 1)res = res * x;	x = x * x;	n >>= 1; }return res; }
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

#define For(i,a,b)	for(ll (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define rFor(i,a,b)	for(ll (i) = (a-1);i >= (b);(i)--)
#define rrep(i,n)	rFor(i,n,0)
#define each(i,n)	for(auto &i : n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))
#define tostr(a)	tostring(a)
#define dump(val) 	cerr << #val " = " << val << endl;
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

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

const ll mod = 1e9 + 7;
const ll INF = 1e17 + 9;

#define int ll
#define double ld

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

	map<int, int> mp;
	rep(i, 3) {
		int t;
		cin >> t;
		mp[t]++;
	}
	if (mp[5] == 2 && mp[7] == 1) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,ans=-1;
const int N = 505;
char mp[N][N];
bool br[N],bc[N],wr[N],wc[N];
bool flag = 0;
int main(){
	scanf("%d", &n);
	for( int i = 1; i <= n; i++ ){
		scanf("%s", mp[i]+1);
		for( int j = 1; j <= n; j++ )
			if( mp[i][j] == '#' ){ br[i] = bc[j] = flag = 1; }
			else wr[i] = wc[j] = 1;
	}
	if( !flag ){ puts("-1"); return 0; }
	for (int i = 1; i <= n; i ++) {
		int tmp = 0 ;
		if (!bc[i]) tmp = 1 ; 
		for( int j = 1; j <= n; j++ )if( mp[i][j] == '.' )tmp++;
		for( int j = 1; j <= n; j++ )if( wc[j] ) tmp++;
		if( tmp < ans || ans == -1 ) ans = tmp ; 
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll mod = 1000000007;
 
int main() {
  int n,a,b,c,d;
  cin >> n;
  a=n/1000;
  b=n/100-a*10;
  c=n/10-a*100-b*10;
  d=n%10;
  vector<char>s(2);
  s[0]='+';
  s[1]='-';
   for(int j=0; j<2; j++){
    for(int k=0; k<2; k++){
     for(int l=0; l<2; l++){
       int ans = a;
       if(j==0) ans+=b;
       else ans-=b;
       if(k==0) ans+=c;
       else ans-=c;
       if(l==0) ans+=d;
       else ans-=d;
       if(ans==7){
        cout << a << s[j] << b << s[k] << c << s[l] << d << "=7" << endl;
        return 0;
       }
     }
    }
   }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<map>
using namespace std;

int main()
{
	int a, b, c;
	int flag = 0;
	cin >> a >> b >> c;

	for (int i = 0;i < 1000000;i++)
	{
		if ((a * i )% b == c)
		{
			flag = 1;
			break;
		}
	}
	if (flag == 1)
		cout << "YES";
	else
		cout << "NO";
}

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

int N; pair<int, int> a[100002];
int main(){
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%d",  &a[i].first); a[i].second = i+1;
    }
    sort(a, a+N);
    for (int i = 0; i < N; i++) {
        printf("%d ", a[i].second);
    }
    return 0;
}

Measured memory_bytes: 1536
import java.util.*;

class Main{
	public static void main(String[] args){
		int s[]=new int[3];
		Scanner sc = new Scanner(System.in);
		
		for(int i=0;i<s.length;i++){
			s[i]= sc.nextInt();
		}
		int a = s[0];
		int b = s[1];
		int c = s[2];
		int cnt = 0;
		for(int i = a; i <= b; i++){
			if((c % i) == 0){
				cnt++;
			}
		}
				
		System.out.println(cnt);
	}
}

Measured memory_bytes: 17312
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
vector<ll> c_pos[27];
bool isused[27];
int main(){
  string s,t;
  cin>>s>>t;
  ll ans=0;
  for(ll i=0;i<27;i++) isused[i]=false;
  for(ll i=0;i<(ll)s.length();i++){
    ll cn=(int)(s[i]-'a');
    c_pos[cn].push_back(i);
    isused[cn]=true;
  }
  ll np=-1;
  for(ll i=0;i<(ll)t.length();i++){
    ll tn=(int)(t[i]-'a');
    if(!isused[tn]){
      cout<<-1<<endl;
      return 0;
    }
    ll sz=(ll)(upper_bound(c_pos[tn].begin(),c_pos[tn].end(),np)-c_pos[tn].begin());
    //cout<<"s:"<<sz<<endl;
    if(sz==c_pos[tn].size()){
      ans+=(ll)s.length();
      np=c_pos[tn][0];
      //cout<<ans<<" "<<np<<endl;
    }
    else{
      np=c_pos[tn][sz];
      //cout<<np<<endl;
    }
  }
  cout<<(ll)(ans+np+(ll)1)<<endl;
}


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

void chmin(int &a, int b) {
  if (a > b) a = b;
}

void solve() {
  vector<vector<int>> f(401, vector<int>(401, 2e9));
  f[0][0] = 0;
  int n, ma, mb;
  cin >> n >> ma >> mb;
  for (int i = 1; i <= n; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    for (int j = 400; j >= a; j--)
    for (int k = 400; k >= b; k--) {
      chmin(f[j][k], f[j - a][k - b] + c);
    }
  }
  int ans = 2e9;
  for (int i = 1; ma * i <= 400 && mb * i <= 400; i++) {
    chmin(ans, f[ma * i][mb * i]);
  }
  if (ans == 2e9) ans = -1;
  cout << ans << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


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

int A1,A2,A3;
int sum = 0;
int main(){
  std::cin >> A1 >> A2 >> A3;
  sum = A1 + A2 + A3;
    if(sum >= 22){
      std::cout << "bust" << std::endl;
    }else{
      std::cout << "win" << std::endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<climits>
#include<set>
#include<utility>
using namespace std;
typedef long long int ll;
const ll MOD=1e9+7;

int main(){

	int n, k, ans=1;
	cin >> n >> k;

	for(int i=0; i<n; i++){
		if(ans*2<=ans+k){
			ans*=2;
		} else {
			ans+=k;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
def main():
    import sys
    input=sys.stdin.readline
    n,m=map(int,input().split())
    e=[(int(input().split()[0]),[2**(n-i)for i in map(int,input().split())])for _ in range(m)]
    I=9**9
    dp=[I]*2**n
    dp[0]=0
    for i,dpi in enumerate(dp):
        if dpi==I:continue
        for a,c in e:
            b=i
            for j in c:b|=j
            cost=dpi+a
            if dp[b]>cost:dp[b]=cost
    print(-(dp[-1]==I)or dp[-1])
main()

Measured memory_bytes: 3440