akhauriyash/Code-Regression huggingface dataset:
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
int main(void){
    int a, b;
    cin >> a >> b;
    if(a + b == 15){
        cout << "+" << endl;
    } else if(a * b == 15){
        cout << "*" << endl;
    } else {
        cout << "x" << endl;
    }
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int N0 = N;
  
  int sum_digit = 0;
  while (true) {
    sum_digit += N0%10;
    N0 /= 10;
    if (N0 == 0)
      break;
  }
  //cout << sum_digit << endl;
  
  if (N%sum_digit == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int n = 0;
        int w = 0;
        int e = 0;
        int s = 0;
        for (int i = 0; i < S.length(); i++) {
            char c = S.charAt(i);

            if( c == 'W')  {
                w++;
            } else if( c == 'E' )  {
                e++;
            } else if( c == 'N' ) {
                n++;
            } else {
                s++;
            }
        }

        boolean ns = n == 0 && s == 0 || n != 0 && s != 0;
        boolean we = w == 0 && e == 0 || w != 0 && e != 0;
        System.out.println(ns&&we?"Yes":"No");
    }
}


Measured memory_bytes: 24020
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - 和風いろはちゃんイージー / Iroha and Haiku (ABC Edition)
            var words = ReadLine();

            if (words.Sum() == 17)
            {
                if (words.Contains(5) && words.Contains(7))
                {
                    Console.WriteLine("YES");
                    return;
                }
            }

            Console.WriteLine("NO");
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 11220
#include <stdio.h>

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

    int s[n], r[n];
    int count1 = 0;
    int count2 = 0;
    for(int i = 0; i < n; i++){
        scanf("%d", &s[i]);
        if(s[i] % 2 == 0){
            count1++;
        }
    }


    for(int i = 0; i < n; i++){
           if(s[i] % 6 == 0 || s[i] % 10 == 0){
                count2++;
            }
    }

    if(count1 == count2){
        printf("APPROVED");
    }else{
        printf("DENIED");
    }
    
    
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std; 
#define priority_queue pq;
#define int long long
#define pu push
#define loop for(int i=0;i<n;i++)
int32_t main(){
string n;
cin>>n;
int flag=0;
if(n[2]==n[3])
flag++;
if(n[5]==n[4])
flag++;
if(n.length()==6)
flag++;    
if(flag==3)
    cout<<"Yes";
else
    cout<<"No";
}


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

int main(){
  long long n;
  cin>>n;
  long long a[n];
  long long s[n];
  long long suma=0;
  for(long long i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a,a+n);
  for(long long i=0;i<n;i++){
    suma=suma+a[i];
    s[i]=suma;
  } 
    
    
  long long cnt=1;
  for(int i=n-1;i>=1;i--){
    if(a[i]<=2*s[i-1]){
      cnt++;
    }
    else break;
  }
  cout<<cnt<<endl;
  return 0;
}

  
    

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007
typedef long long ll;

int main() {
    int n,l;cin>>n>>l;
    int sum=0,min=mod,absmin=mod;

    rep(i,n){
        sum+=l+i;
        if(abs(l+i)<absmin){
            absmin=abs(l+i);
            min=l+i;
        }
    }

    cout<<sum-min<<endl;
}



Measured memory_bytes: 256
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			long t = scanner.nextLong();
			long[] a = new long[n];
			IntStream.range(0, n).forEach(i -> a[i] = scanner.nextLong());
			System.out.println(IntStream.range(1, n).mapToLong(i -> Math.min(a[i] - a[i - 1], t)).sum() + t);
		}
	}
}


Measured memory_bytes: 93328
def main():
    from sys import stdin
    from builtins import range

    readline = stdin.readline

    H, W = map(int, readline().split())
    S = [readline()[:-1] + '#' for _ in range(H)]

    S.append('#' * W)
    ft = [[i] * i for i in range(100)]
    yoko = [[0] * W for _ in range(H)]
    for i in range(H):
        start = -1
        si = S[i]
        yokoi = yoko[i]
        for j in range(W + 1):
            if si[j] == '#':
                if start != -1:
                    t = j - start
                    if t < 100:
                        yokoi[start:j] = ft[t]
                    else:
                        yokoi[start:j] = [t] * t
                    start = -1
            else:
                if start == -1:
                    start = j

    result = 0
    for i in range(W):
        start = -1
        for j in range(H + 1):
            if S[j][i] == '#':
                if start != -1:
                    t = yoko_max + j - start - 1
                    if t > result:
                        result = t
                    start = -1
            else:
                yji = yoko[j][i]
                if start == -1:
                    start = j
                    yoko_max = yji
                else:
                    if yji > yoko_max:
                        yoko_max = yji
    print(result)


main()


Measured memory_bytes: 40820
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

vector<vector<int>> g;
vector<int> dp;
void dfs(int u, int p) {
    dp[u] = 0;
    for (int v: g[u]) if (v != p) {
        if (!~dp[v]) dfs(v, u);
        chmax(dp[u], dp[v] + 1);
    }
}

int main() {
    int n, m; cin >> n >> m;
    g.resize(n);
    while (m--) {
        int x, y; cin >> x >> y; x--, y--;
        g[x].emplace_back(y);
    }
    dp.assign(n, -1);
    for (int i = 0; i < n; i++) if (!~dp[i]) dfs(i, -1);
    cout << *max_element(dp.begin(), dp.end()) << endl;
    return 0;
}

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

int main() {
  string s,t;
  int length, i;
  bool judge = 0;
  
  cin >> s >> t;
  
  length = s.size();
  if (length > t.size()) length = t.size();
  
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  
  for (i = 0; i < length; i++) {
    if (t.at(i) > s.at(i)) {
      judge = 1;
      break;
    }
    if ((i == length - 1) && (s.at(i) == t.at(i)) && (s.size() < t.size())) judge = 1;
  }
  
  if (judge) cout << "Yes" << endl;
  else cout << "No" << endl;  
}

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

int main(){
  set<int> s;
  for(int i=0;i<4;i++){
    int x;
    cin>>x;
    s.insert(x);
  }
  
  if(s.count(1)==1&&s.count(9)==1&&s.count(7)==1&&s.count(4)==1){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 3592
#define _USE_MATH_DEFINES  

#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <vector>

int main(){
    long long min = 1000000, max = -1000000, sum = 0, n, val;
    
    std::cin >> n;

    for(int i = 0; i < n; ++i){
        std::cin >> val;
        min = std::min(val, min);
        max = std::max(val, max);
        sum += val;
    }

    std::cout << min << " " << max << " " << sum << std::endl;

    return 0;
}


Measured memory_bytes: 3108
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <ctype.h>
#include <string>
#include <iostream>
#include <vector>
#include <stack>
#include <fstream>
#include <sstream>
#include <queue>
#include <exception>
#include <cmath>
#include <numeric>
#include <map>
#include <algorithm>
#include <bitset>
#include <set>
#include <functional>

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

using namespace std;
typedef long long int lint;
typedef vector< vector < char > > Mat;

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

void AOJ0141(bool newline)
{
	int n;
	cin >> n;

	if (newline) cout << endl;

	if (n == 1) {
		cout << "#" << endl;
		return;
	}
	if (n == 2) {
		cout << "##" << endl;
		cout << "# " << endl;
		return;
	}

	vector<int> steps;

	steps.push_back(n - 1);
	for (int i = n - 1; i > 0; i -= 2) {
		steps.push_back(i);
		steps.push_back(i);
	}
	if (n % 2 == 0) {
		steps.pop_back();
	}

	Mat spiral(n);
	REP(i, n) spiral[i] = vector<char>(n, ' ');
	int x = 0;
	int y = n - 1;

	spiral[y][x] = '#';

	REP(i, steps.size()) {
		REP(s, steps[i]) {
			x += dx[i % 4];
			y += dy[i % 4];
			spiral[y][x] = '#';
		}
	}

	REP(i, n) {
		REP(j, n) {
			cout << spiral[i][j];
		}
		cout << endl;
	}

	return;
}

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

	bool newline = false;
	REP(i, d) {
		AOJ0141(newline);
		newline = true;
	}

	return 0;
}

Measured memory_bytes: 3080
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
  int N, T;
  cin >> N >> T;
  vector <int> cost;
  for (int i = 0; i < N; i++) {
    int c, t;
    cin >> c >> t;
    if (t <= T) cost.push_back(c);
  }
  if (cost.size()==0) {
    cout << "TLE" << endl;
    return 0;
  }
  sort(cost.begin(), cost.end());
  cout << cost[0] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
using namespace std;
#define INT_MAX 2147483647
#define INT_MIN -2147483648
#define INF 100000000
#define _INF -100000000
#define INFLL (long long)1e14
#define _INFLL (long long)-1e14
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int,int> P;

struct node {
	bool done;
	vi to;
	int id, from;
	int pre, low;
};

class lowlink {
	vector<node> nodes;
	int ord;
	vector<P> bridges;
public:
	lowlink(vector<node> A) {
		nodes = A;
	}

	void dfs(int a) {
		nodes[a].done = 1;
		nodes[a].pre = ord;
		nodes[a].low = ord;
		ord++;
		Loop(i, nodes[a].to.size()) {
			int b = nodes[a].to[i];
			if (b == nodes[a].from) continue;
			if (!nodes[b].done) {
				nodes[b].from = a;
				dfs(b);
			}
			if (nodes[a].low > nodes[b].low) nodes[a].low = nodes[b].low;
			if (nodes[a].pre < nodes[b].low) bridges.push_back({ nodes[a].id,nodes[b].id });
		}
		return;
	}
	void find_bridge() {
		ord = 0;
		dfs(0);
		Loop(i, bridges.size()) {
			if (bridges[i].first > bridges[i].second) swap(bridges[i].first, bridges[i].second);
		}
		sort(bridges.begin(), bridges.end());
		Loop(i, bridges.size()) {
			cout << bridges[i].first << " " << bridges[i].second << endl;
		}
	}
};

int main() {
	int v, e; cin >> v >> e;
	vector<node> nodes(v);
	Loop(i, v) nodes[i] = { 0,{}, i,-1,-1,-1 };
	Loop(i, e) {
		int s, t;
		cin >> s >> t;
		nodes[s].to.push_back(t);
		nodes[t].to.push_back(s);
	}
	lowlink lk(nodes);
	lk.find_bridge();
}

Measured memory_bytes: 6032
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int n;
int f[9][9];
int ans[9][9];
int check(int x,int y)
{
	for(int i=0;i<9;i++)
	{
		if(i==y)continue;
		if(f[x][i]==f[x][y])return 1;
	}
	for(int i=0;i<9;i++)
	{
		if(i==x)continue;
		if(f[i][y]==f[x][y])return 1;
	}
	int nx=x,ny=y;
	while(nx%3!=0)nx--;
	while(ny%3!=0)ny--;
	for(int i=nx;i<nx+3;i++)
	{
		for(int j=ny;j<ny+3;j++)
		{
			if(i==x&&j==y)continue;
			if(f[i][j]==f[x][y])return 1;
		}
	}
	return 0;
}
int main()
{
	cin >> n;
	for(int s=0;s<n;s++)
	{
		memset(ans,0,sizeof(ans));
		for(int i=0;i<9;i++)
		{
			for(int j=0;j<9;j++)
			{
				cin >> f[i][j];
			}
		}
		for(int i=0;i<9;i++)
		{
			for(int j=0;j<9;j++)
			{
				ans[i][j]=check(i,j);
			}
		}
		for(int i=0;i<9;i++)
		{
			for(int j=0;j<9;j++)
			{
				if(ans[i][j])printf("*%d",f[i][j]);
				else printf(" %d",f[i][j]);
			}
			puts("");
		}
		if(s!=n-1)puts("");
	}
	return 0;
}

Measured memory_bytes: 1148
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	if(n<1200){
		cout<<"ABC"<<endl;return 0;
	}
	else if(n<2800){
		cout<<"ARC"<<endl;return 0;
	}
	else{
		cout<<"AGC"<<endl;return 0;
	}
	return 0;
}



Measured memory_bytes: 256
// Author: 23forever
#include <bits/stdc++.h>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define fi first
#define se second
typedef long long LL;
const int MAXN = 5000;
const int P = 1e9 + 7;
using namespace std;

inline int read() {
  int x = 0; char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  return x;
}

int dp[MAXN + 5][MAXN + 5], g[MAXN + 5];

namespace tree {

int tot, head[MAXN + 5];

const int MAXM = 2 * MAXN;

struct Edge {
  int to, nxt;
  Edge() {}
  Edge(int _to, int _nxt) : to(_to), nxt(_nxt) {}
} edge[MAXM + 5];

void addEdge(int u, int v) {
  edge[tot] = Edge(v, head[u]), head[u] = tot++;
  edge[tot] = Edge(u, head[v]), head[v] = tot++;
}

void init() {
  tot = 0, memset(head, -1, sizeof(head));
}

int tmp[MAXN + 5], sz[MAXN + 5];

void dfs(int u, int fa) {
  dp[u][1] = 1; sz[u] = 1;

  for (int i = head[u]; ~i; i = edge[i].nxt) {
    int v = edge[i].to;
    if (v == fa) continue;
    dfs(v, u);

    for (int j = 1; j <= sz[u] + sz[v]; ++j) tmp[j] = 0;
    for (int j = 1; j <= sz[u]; ++j) {
      for (int k = 0; k <= sz[v]; ++k) {
        tmp[j + k] = (tmp[j + k] + 1LL * dp[u][j] * dp[v][k] % P) % P;
      }
    }
    for (int j = 1; j <= sz[u] + sz[v]; ++j) dp[u][j] = tmp[j];

    sz[u] += sz[v];
  }

  for (int i = 2; i <= sz[u]; i += 2) {
    dp[u][0] = (dp[u][0] - 1LL * dp[u][i] * g[i] % P + P) % P;
  }
}

}

int n;

void init() {
  n = read();
  tree::init();

  for (int i = 1; i < n; ++i) {
    int u = read(), v = read();
    tree::addEdge(u, v);
  }
}


int main() {
#ifdef forever23
  freopen("test.in", "r", stdin);
  freopen("test.out", "w", stdout);
#endif
  init();

  g[0] = 1;
  for (int i = 2; i <= n; i += 2) { 
    g[i] = 1LL * g[i - 2] * (i - 1) % P;
  }
  tree::dfs(1, 0);
  printf("%d\n", (0 - dp[1][0] + P) % P);

#ifdef forever23
	printf("Running Time = %d ms\n", int(clock() * 1000.0 / CLOCKS_PER_SEC));
#endif
  return 0;
}

Measured memory_bytes: 97280
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
	string s;cin >> s;
	char a = s[0];
	char b;
	bool flag = false;
	bool batu = true;
	for(int i = 1; i < s.size(); i++){
		if(s[i] == a){
			continue;
		}else if(!flag){
			flag = true;
			b = s[i];
		}
		if(flag){
			if(s[i] != b && s[i] != a){
				batu = false;
				break;
			}
		}
	}
	cout <<((batu && flag) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
f = 9 - ((a - 1) % 10)
g = 9 - ((b - 1) % 10)
h = 9 - ((c - 1) % 10)
i = 9 - ((d - 1) % 10)
j = 9 - ((e - 1) % 10)
print(a + b + c + d + e + f + g + h + i + j - max(f, g, h, i, j))

Measured memory_bytes: 3064
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Deque<Long> deque  = new ArrayDeque<Long>();
		for (int i=0;i<n;i++) {
			if (i%2==0) {
				deque.add(sc.nextLong());
			} else {
				deque.push(sc.nextLong());
			}
		}
		if (n%2==0) {
			while (deque.isEmpty()==false) {
				System.out.print(deque.pollFirst()+" ");
			}
		} else {
			while (deque.isEmpty()==false) {
				System.out.print(deque.pollLast()+" ");
			}
		}
	}
}

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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define lfs <<fixed<<setprecision(10)<<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
template<typename T>
void emp(map<T,ll>&m, T x){m.emplace(x,0).first->second++;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll>a(n),b(n),c(n);
  rep(i,0,n)cin>>a[i]>>b[i]>>c[i];
  auto dp=make_v(n,3,0);
  dp[0][0]=a[0];
  dp[0][1]=b[0];
  dp[0][2]=c[0];
  rep(i,1,n){
    dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
    dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
    dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];
  }
  cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]})<<endl;
  return 0;
}

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

using namespace std;

int main() {
	int x;
	scanf("%d", &x);
	
	bool ok = 0;
	
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			if (i * j == x) ok = 1;
		}
	}
	
	if (ok) printf("Yes\n");
	else printf("No\n");
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    int N, L;
    cin >> N >> L;
    int sum = 0;
    FOR(i, 1, N + 1) sum += L + i - 1;

    int ans = INF;
    FOR(i, 1, N + 1) {
        const auto cur = abs(ans - sum);
        const auto nxt = abs((sum - (L + i - 1)) - sum);
        if (nxt < cur) ans = sum - (L + i - 1);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>

using namespace std;

int main() {
	string a;
	int k1,k2;
	int wa1,wa2;

	for (int i = 0; i < 9; i++) {
		cin >> a >> k1 >> k2;
		wa1 = k1 + k2;
		wa2 = k1 * 200 + k2 * 300;
		cout << a << " " << wa1 << " " << wa2 << endl;
	}
	return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ll N, M;
    cin >> N >> M;
    bool possible = true;
    ll ans = 1;
    if (N - M >= 2 || M - N >= 2) possible = false;
    else if (N - M == 1 || M - N == 1){
        for (ll i = 1; i <= N; i++){
            ans = (ans * i) % 1000000007;
        }
        for (ll i = 1; i <= M; i++){
            ans = (ans * i) % 1000000007;
        }
    }
    else{
        ll odd = 1;
        ll even = 1;
        for (ll i = 1; i <= N; i++){
            odd = (odd * i) % 1000000007;
            even = (even * i) % 1000000007;
        }
        ans = (2 * ((odd * even) % 1000000007)) % 1000000007;
    }
    if (possible) cout << ans << endl;
    else cout << 0 << endl;
}



Measured memory_bytes: 256
def solve(depth, left_w):
	if depth == 4:
		return 0
	res = solve(depth+1, left_w)
	r = 0
	for vi in w4[depth]:
		left_w -= w0+depth
		if left_w < 0:
			break
		r += vi
		res = max(res, r + solve(depth+1, left_w))
	return res

n,w = map(int, raw_input().split())

w4 = [[] for i in xrange(4)]
for i in xrange(n):
	wi,vi = map(int, raw_input().split())
	if i == 0:
		w0 = wi
	w4[wi-w0].append(vi)
	
for ww in w4:
	ww.sort()
	ww.reverse()

ans = solve(0,w)
print ans


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<string, string> P;
typedef pair<ll, pair<ll, ll> > P3;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(1e5) + 5;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)

int main() {
    int n;
    string s, sl, sr;
    cin >> n >> s;
    sl = s.substr(0, n);
    sr = s.substr(n, n);
    reverse(sr.begin(), sr.end());
    map<P, ll> mpl, mpr;
    for (int i = 0; i < (1 << n); i++) {
        P l, r;
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) {
                l.first += sl[j];
                r.first += sr[j];
            } else {
                l.second += sl[j];
                r.second += sr[j];
            }
        }
        mpl[l]++;
        mpr[r]++;
    }
    ll cnt = 0;
    for (auto itr : mpl) {
        P p = itr.first;
        cnt += mpl[p] * mpr[p];
    }
    cout << cnt << endl;
    return 0;
}


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

long long a, b, c, d;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> a >> b >> c >> d;
	if(c < a) swap(a, c), swap(b, d);
	if(b <= 0 && c >= 0) cout << b * c << '\n';
	else cout << max(a * c, b * d) << '\n';
	return 0;
}

Measured memory_bytes: 3628
#include "cstdio"
long long n,x,ss;
long long dfs(long long a,long long b){
	if(a%b==0){
		return(a<<1)-b;
	}
	return a/b*b*2+dfs(b,a%b);
}
int main(){
	scanf("%lld%lld",&n,&x);
	if(x>=n-x)printf("%lld\n",n+dfs(x,n-x));
	else printf("%lld\n",n+dfs(n-x,x));
}

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

#include <string>
#include <vector>
#include <algorithm>
int main(){
    int n;
    string str;
    cin >> n >> str;
    vector<char> cs{str.at(0)};
    int count=1;
    for(int i=1; i<n; i++) {
        if(cs.at(count-1)!=str.at(i)){
            cs.push_back(str.at(i));
            count++;
        }
    }
    cout << cs.size() << endl;
}

Measured memory_bytes: 3796
n, k = map(int, input().split())
x = list(map(int, input().split()))
sec = 3 * 10**8
for i in range(n - k + 1):
    if x[i] * x[i + k - 1] < 0:
        sec = min(sec, abs(x[i]*2) + x[i + k - 1], abs(x[i]) + x[i + k - 1] * 2)
    else:
        sec = min(sec, max(abs(x[i]), abs(x[i + k - 1])))
print(sec)

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

int main()
{
    long long int b, r, n, br, div, rem, b_rem, res;

    //while(1){
    cin>>n>>b>>r;

    br = b+r;

    div = n/br;
    rem = n%br;

    if(b == 0)
        res = 0;
    else if(n<b)
        res = n;
    else if(rem == 0)
        res = div*b;
    else if(rem!=0 && rem>=b)
        res = div*b + b;
    else
        res = div*b + rem%b;

    cout<<res<<endl;    //}

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cmath>
#include<map>
#include<set>
using namespace std;
const int INF = 1 << 29;
const double EPS = 1e-9;

typedef long long ll;

#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)

string S;

int main(int argc, char * argv[])
{
    ios::sync_with_stdio(false);
	cin >> S;
	string ret = "";
	rep(i,S.size()){
		if (S[i]=='0' || S[i]=='1')
			ret = ret + S[i];
		else if (ret.size() != 0)
			ret.erase(--ret.end());
	}
	cout << ret << endl;


    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
int a,b,c;
cin>>a>>b>>c;
if(a==b && b==c) cout<<"Yes"<<'\n';
else cout<<"No"<<'\n';
return 0;
}

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

using namespace std;

int main(){
	int a,b,c;
	cin >> a >> b >> c;
	bool stat[3600];
	int n = 0;
	for(int i = 0;i < 3600;i++){
		for(int j = 0;j < a;j++){
			stat[n] = true;
			n++;
			if(n >= 3600) break;
		}
		if(n >= 3600) break;
		for(int j = 0;j < b;j++){
			stat[n] = false;
			n++;
			if(n >= 3600) break;
		}
		if(n >= 3600) break;
	}
	
	int ans = 0;
	for(int i = 0;i < 3600;i++){
		int arr = i * 60 + c;
		if(arr > 3600){
			ans = -1;
			break;
		}
		if(stat[arr - 1]){
			ans = arr;
			break;
		}
	}
	
	cout << ans << endl;
	return 0;
}


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

int main() {
  int N;
  string S;
  cin >> N >> S;
  vector<long long int> V(26, 0);
  for (int i = 0; i < N; i++) V.at(S.at(i) - 'a')++;
  long long int ans = 1, MOD = 1000000007;
  for (int i = 0; i < 26; i++) ans = ans * (V.at(i) + 1) % MOD;
  ans = (ans + MOD - 1) % MOD;
  cout << ans << endl;
}

Measured memory_bytes: 3692
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<unistd.h>
#include <array>
#include <map> 
#define ALL(a)  (a).begin(),(a).end()



using namespace std;
typedef long long ll;
struct point{
  int x;
  int y;

};
int gcd(int a, int b)
{
	return a == 0 ? b : gcd(b % a, a);
}
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int input(){
  int x;
  cin>>x;
  return x;
}

int moji(char in)
{
    int ans = (int)in-(int)'a';
    if((ans < 0) || (ans > 25)){
        ans = 26;
    }
    return ans;
}
const int VV=10;//場合に応じてVVの値のみ変更する必要あり
//dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能
int cost[VV][VV];
int d[VV];
bool used[VV];
void dijkstra(int s){
  fill(d,d+VV,100000);
  fill(used,used+VV,false);
  d[s]=0;
  while(true){
    int v=-1;
    for(int u=0;u<VV;u++){
      if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
    }
    if(v==-1)break;
    used[v]=true;
    for(int u=0;u<VV;u++){
      d[u]=min(d[u],d[v]+cost[v][u]);
    }
  }

}

int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int*)a - *(int*)b;
}

int binary_searchh(long long x,long long k[],int n){
  int l=0;
  int r=n;
  while(r-l>=1){
    int i=(l+r)/2;
    if(k[i]==x)return i;
    else if(k[i]<x)l=i+1;
    else r=i;
  }
  return -1;
}

struct File {
    int aa;
    int bb;

    File(const int& aa, const int& bb)
        : aa(aa), bb(bb) {}
};

bool operator<(const File& a, const File& b)
{
    // ファイル種別、ファイル名の順番で優先順位を付けて比較
    return std::tie(a.aa, a.bb) < std::tie(b.aa, b.bb);
}

long long kaijo(long long x){
  long long l=10*10*10*10*10*10*10*10*10+7;
  long long sum=1;
  for(int i=x;i>0;i--){
    sum*=i;
    if(sum>l){
      sum%=l;
    }
  }
  return sum;
}






int main(){
  long long A,B,C;
  cin>>A>>B>>C;
  if(A%2==1&&B%2==1&&C%2==1){
    long long x[3];
    x[0]=A;
    x[1]=B;
    x[2]=C;
    sort(x,x+3);
    cout<<x[0]*x[1]<<endl;
  }else{
    cout<<0<<endl;
  }

}





  

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main()
{
	char s[6], r[5][8], d;
	int n, i, j, c, b = 0;
	while (cin >> n)
	{
		if (cin.eof()) break;
		if (b) cout << endl;
		sprintf(s, "%05d", n);
		for (i = 0; i < 5; i++)
		{
			d = (char)s[i];
			c = atoi(&d);
			if (c < 5)
			{
				r[i][0] = '*';
				r[i][1] = ' ';
			}
			else
			{
				r[i][0] = ' ';
				r[i][1] = '*';
			}
			r[i][2] = '=';
			for (j = 3; j < 8; j++)
			{
				if (c != j-3 && c != j+2)
					r[i][j] = '*';
				else
					r[i][j] = ' ';
			}
		}
		for (i = 0; i < 8; i++)
		{
			for (j = 0; j < 5; j++)
			{
				cout << r[j][i];
			}
			cout << endl;
		}
		b = 1;
	}
}

Measured memory_bytes: 908
k,n=list(map(int,input().split()))
a=list(map(int,input().split()))
x=0
y=0

for i in range(n):
    if i==1:
        x=a[i]-a[i-1]
        y=i
    elif a[i]-a[i-1]>x:
        x=a[i]-a[i-1]
        y=i

if k-a[n-1]+a[0]>x:
    x=k-a[n-1]+a[0]
    y=0

print(k-x)

Measured memory_bytes: 26444
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N;
int dp[100001];
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  vector<int> vs;
  vs.pb(1);
  for (int i=6; i<=N; i*=6) vs.pb(i);
  for (int i=9; i<=N; i*=9) vs.pb(i);
  rep(i, N+1) dp[i] = INF;
  dp[0] = 0;
  for (int x : vs) {
    for (int j=0; j+x<=N; j++) dp[j+x] = min(dp[j+x], dp[j]+1);
  }
  cout << dp[N] << "\n";
  return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define Alint(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1ll << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 998244353, INF = 1e9;

struct edge { lint to, cap, rev; };

vector<edge> Graph[20005];
int level[20005];
int iter[20005];
void add_edge(lint from, lint to, lint cap) {
	Graph[from].push_back({ to, cap, SZ(Graph[to]) });
	Graph[to].push_back({ from, 0, SZ(Graph[from]) - 1 });
}
void bfs(lint s) {
	memset(level, -1, sizeof(level));
	queue<lint> que;
	que.push(s);
	level[s] = 0;
	while (!que.empty()) {
		lint v = que.front(); que.pop();
		REP(i, SZ(Graph[v])) {
			edge& e = Graph[v][i];
			if (e.cap > 0 && level[e.to] < 0) {
				level[e.to] = level[v] + 1;
				que.push(e.to);
			}
		}
	}
}

lint dfs(lint v, lint t, lint f) {
	if (v == t) return f;
	for (int& i = iter[v]; i < SZ(Graph[v]); i++) {
		edge& e = Graph[v][i];
		if (e.cap > 0 && level[v] < level[e.to]) {
			lint d = dfs(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				Graph[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

lint max_flow(lint s, lint t) {
	lint flow = 0;
	for (;;) {
		bfs(s);
		if (level[t] < 0) return flow;
		memset(iter, 0, sizeof(iter));
		lint f;
		while ((f = dfs(s, t, INF)) > 0) {
			flow += f;
		}
	}
}

lint X, Y, E, x, y;
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	lint N = 100, s = 200, t = 201;
	cin >> X >> Y >> E;
	REP(i, X) {
		add_edge(s, i, 1);
	}
	REP(i, E) {
		cin >> x >> y;
		add_edge(x, y + N, 1);
	}
	REP(i, Y) {
		add_edge(i + N, t, 1);
	}
	cout << max_flow(s, t) << endl;
}



Measured memory_bytes: 4228
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define fi first
#define se second
#define pii pair<int,int>
#define int long long
#define endl '\n'
#define pll pair<long long,long long>
#define LONGLONG_MAX 100000000000000
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%mod;}
                a=(a*a)%mod;
                b>>=1;
        }
    return ans;
        
}
bool check(string s,int i,int j){
    while(i<j){
        if(s[i]!=s[j])return false;
        i++;j--;
    }
    return true;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    srand(time(0));
    int n;
    cin>>n;
    int a[n];
    int b[n]={0};
    for(int i=0;i<n;i++){
        cin>>a[i];
        b[a[i]-1]++;
        a[i]--;
    }
    int ans=0;
    for(int i=0;i<n;i++){
        ans+=(b[i]*(b[i]-1))/2;
    }
    for(int i=0;i<n;i++){
        cout<<ans-b[a[i]]+1<<endl;
    }
    return 0;
}


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

int main() {
  int N,X,T;
  cin>>N>>X>>T;
  int kai = N/X;
  if(kai*X==N){
    cout<<kai*T<<endl;
  }
  else{
    kai += 1;
    cout<<kai*T<<endl;
  }
}

Measured memory_bytes: 3560
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;

struct edge{
	int to, cost;
	edge(int to_, int cost_){
		to = to_; cost = cost_;
	}
};
const int MAX_N = 101;
const int MAX_M = 1001;
const int INF = 1e+8;
vector<edge> G[MAX_N];
// memo[k][v] := 頂点 v までたどり着くのに k 回エッジのコストを 0 にした状態を探索したかどうか.
bool memo[MAX_M][MAX_N];
int n, m, c;

struct State{
	// cost := コスト, e := エッジのコストを変更した回数, v := 頂点
	int cost, e, v;  
	State(int cost_, int e_, int v_){
		cost = cost_; e = e_; v = v_;
	}
};
bool operator<(const State& a, const State& b){
	return a.cost > b.cost;
}

int solve(){
	for(int i=0 ; i < MAX_M ; i++ ) fill(memo[i], memo[i]+MAX_N, false);
	
	priority_queue<State> q;
	q.push( State(0, 0, 0) );
	int res = INF;
	while( !q.empty() ){
		int cost = q.top().cost, e = q.top().e, v = q.top().v; q.pop();
		
		if( memo[e][v] ) continue;
		memo[e][v] = true;
		
		if( v == n-1 ){ // ゴールの時
			res = min(res, e);
			continue;
		}
		
		for(int i=0 ; i < G[v].size() ; i++ ){
			int to = G[v][i].to;
			int next_cost = cost + G[v][i].cost;
			
			if( !memo[e][to] && next_cost <= c ){ // エッジのコストを変更しない
				q.push( State(next_cost, e, to) );
			}
			next_cost -= G[v][i].cost;
			if( !memo[e+1][to] && e+1 <= n ){ // エッジのコストを変更する
				q.push( State(next_cost, e+1, to) );
			}
		}
	}
	return res;
}

void add_edge(int u, int v, int cost){
	G[u].push_back( edge(v, cost) );
}

int main(){
	while( cin >> n >> m >> c , n || m || c ){
		for(int i=0 ; i < MAX_N ; i++ ) G[i].clear();
		
		for(int i=0 ; i < m ; i++ ){
			int u, v, cost;
			cin >> u >> v >> cost;
			u--; v--;
			add_edge(u, v, cost);
		}
		cout << solve() << endl;
	}
}

Measured memory_bytes: 2488
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}

vector<int> memof(100100, 0);
int f(int N)
{
  if (N < 0) return 0;
  if (N == 0) return 1;
  if (N == 1) return 1;
  if (memof.at(N) > 0) return memof.at(N);
  int r = (f(N - 2) + f(N - 1)) % MOD;
  memof.at(N) = r;
  return r;
}

signed main()
{
  int N, M;
  cin >> N >> M;

  int ans = 1;
  int a0 = -1;
  for (int i = 0; i < M; i++)
  {
    int a;
    cin >> a;
    ans *= f(a - a0 - 2);
    ans %= MOD;
    a0 = a;
  }
  ans *= f(N - a0 - 1);
  ans %= MOD;
  
  cout << ans << endl;
}

Measured memory_bytes: 2560
#include<iostream>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b&&b!=c&&a!=c)
	{
		cout<<"Yes"<<endl;
	}
	else if(a==c&&c!=b&&a!=b)
	{
		cout<<"Yes"<<endl;
	}
	else if(b==c&&c!=a&&a!=b)
	{
		cout<<"Yes"<<endl;
	}
	else
	cout<<"No"<<endl;
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
ll dp[110][200100];
int main(){
    int n,mw;
    cin >> n >> mw;
    vector<ll> v(n);
    vector<ll> w(n);
    rep(i,n){
        cin >> w[i] >> v[i];
    }
    rep(i,n){
        rep(j,mw+1){
            if(j>=w[i]){
                dp[i+1][j] = max(dp[i][j],dp[i][j-w[i]]+v[i]);
            }
            else{
                dp[i+1][j] = max(dp[i][j],dp[i+1][j]);
            }
        }
    }
    cout << dp[n][mw]<<endl;
return 0;
}

Measured memory_bytes: 156416
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int ans=1,n,k;
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){
	    if(ans>k) ans+=k;
	    else ans+=ans;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n,a,b;
    cin>>n>>a>>b;
    if(n>1&&b>=a||n==1&&a==b)
        cout<<(n-2)*(b-a)+1<<endl;
    else
        cout<<0<<endl; 
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int N, C;
	cin >> N >> C;

	vector<vector<lint>> cost(C, vector<lint>(C));
	vector<vector<lint>> count(3, vector<lint>(C));
	vector<vector<lint>> cal(3, vector<lint>(C, 0));

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

	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < N; j++)
		{
			lint tmp;
			cin >> tmp;
			count[(i + j) % 3][tmp - 1]++;
		}
	}

	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < C; j++)
		{
			for (int k = 0; k < C; k++)
			{
				cal[i][k] += count[i][j] * cost[j][k];
			}
		}
	}

	lint ans = INF64;
	for (int i = 0; i < C; i++)
	{
		for (int j = 0; j < C; j++)
		{
			if (i == j)
				continue;

			for (int k = 0; k < C; k++)
			{
				if (i == k)
					continue;
				if (j == k)
					continue;

				ans = min(ans, cal[0][i] + cal[1][j] + cal[2][k]);
			}
		}
	}

	cout << ans << endl;
	return;
}

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

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <queue>
#include <set>
#include <list>

using namespace std;

using i8 = char;
using u8 = unsigned char;
using i32 = int;
using u32 = unsigned int;
using i64 = long long int;
using u64 = unsigned long long int;

using pii = pair<i32, i32>;

#define LOOP_TYPE(s, n) decltype((n) - (s))
#define FOR(i, s, n) for (auto i = LOOP_TYPE(s, n)(s); i != LOOP_TYPE(s, n)(n); i++)
#define FORR(i, s, n) for (auto i = LOOP_TYPE(s, n)(n) - 1; i != LOOP_TYPE(s, n)(s) - 1; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FORR(i, 0, n)
#define mp make_pair

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

class UnionFindTree
{
public:

	UnionFindTree(size_t n)
		: m_parent(n)
		, m_rank(n, 0)
	{
		for (size_t i = 0; i < n; i++) {
			m_parent[i] = static_cast<i32>(i);
		}
	}

	void Unite(i32 x, i32 y)
	{
		x = findParent(x);
		y = findParent(y);
		if (x == y) return;
		if (m_rank[x] < m_rank[y]) {
			m_parent[x] = y;
		} else {
			m_parent[y] = x;
			if (m_rank[x] = m_rank[y]) m_rank[x]++;
		}
	}

	bool InSameGroup(i32 x, i32 y)
	{
		return findParent(x) == findParent(y);
	}

private:

	i32 findParent(i32 x)
	{
		if (m_parent[x] == x) {
			return x;
		} else {
			return m_parent[x] = findParent(m_parent[x]);
		}
	}

	vector<i32> m_parent;
	vector<i32> m_rank;
};

struct edge {
	i32 u;
	i32 v;
	i32 cost;

	edge(i32 u_, i32 v_, i32 cost_): u(u_), v(v_), cost(cost_)
	{}
};

i32 Kruskal(vector<edge> &edges, size_t num_vertices)
{
	sort(edges.begin(), edges.end(), [](const edge& e1, const edge& e2) {
		return e1.cost < e2.cost;
	});
	UnionFindTree t(num_vertices);
	i32 sumCost = 0;
	for (const auto& e : edges) {
		if (!t.InSameGroup(e.u, e.v)) {
			t.Unite(e.u, e.v);
			sumCost += e.cost;
		}
	}
	return sumCost;
}

int main()
{
	i32 N;
	cin >> N;
	vector<pii> xsorted;
	vector<pii> ysorted;
	REP(i, N) {
		i32 x, y;
		cin >> x >> y;
		xsorted.emplace_back(mp(x, i));
		ysorted.emplace_back(mp(y, i));
	}

	sort(xsorted.begin(), xsorted.end());
	sort(ysorted.begin(), ysorted.end());

	vector<edge> edges;

	REP(i, N - 1) {
		edges.emplace_back(
			xsorted[i].second,	// u
			xsorted[i + 1].second, // v
			xsorted[i + 1].first - xsorted[i].first // cost
		);
		edges.emplace_back(
			ysorted[i].second,	// u
			ysorted[i + 1].second, // v
			ysorted[i + 1].first - ysorted[i].first // cost
		);
	}

	printf("%d\n", Kruskal(edges, N));

	return 0;
}


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

using namespace std;

using i64 = long;

const i64 MOD = 1e9 + 7;
const i64 INF = 1e18 + 7;


signed main(){
    i64 n;
    cin >> n;
    vector<i64> a(n);
    for(auto& x : a)
        cin >> x;

    auto f = [&](bool fl){
        i64 sum = 0;
        i64 cnt = 0;
        for(i64 i = 0; i < n; ++i){
            sum += a[i];
            if(sum == 0){
                ++cnt;
                if(fl)
                    ++sum;
                else
                    --sum;
            }else if(fl && sum < 0){
                i64 t = abs(sum) + 1;
                cnt += t;
                sum = 1;
            }else if(!fl && sum > 0){
                i64 t = abs(sum) + 1;
                cnt += t;
                sum = -1;
            }
            fl ^= 1;
        }
        return cnt;
    };

    cout << min(f(0), f(1)) << endl;
}


Measured memory_bytes: 1024