akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std; 
#define int int64_t
#define itn int
#define fi first
#define se second
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,x;
  int b,ans=0;
  vector<int> a,c;
  cin>>n>>x;
  for(int i=0;i<n;i++){
    cin>>b;
    a.push_back(b);
    if(i!=0){
      c.push_back(a[i-1]+a[i]);
    }
  }
  for(int i=0;i<c.size();i++){
    if(c[i]>x){
      if(c[i]-a[i+1]>x) ans+=a[i+1]+(c[i]-a[i+1]-x),c[i+1]-=a[i+1];
      else ans+=c[i]-x,c[i+1]-=c[i]-x;
    }
  }
  cout<<ans<<"\n";
}
      


Measured memory_bytes: 5124
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
const int N = 1010;
const ll INF = 0x3f3f3f3f3f3f3f3f;
struct edge
{
    int to, cost, next;
}g[N*10];
int cnt, head[N];
int num[N];
ll dis[N];
bool vis[N];
void add_edge(int v, int u, int cost)
{
    g[cnt].to = u, g[cnt].cost = cost, g[cnt].next = head[v], head[v] = cnt++;
}
void spfa(int s, int t, int n)
{
    queue<int> que;
    memset(dis, 0x3f, sizeof dis);
    memset(vis, 0, sizeof vis);
    memset(num, 0, sizeof num);
    que.push(s), dis[s] = 0, vis[s] = true, num[s]++;
    bool flag = false;
    while(! que.empty())
    {
        int v = que.front(); que.pop();
        vis[v] = false;
        for(int i = head[v]; i != -1; i = g[i].next)
        {
            int u = g[i].to;
            if(dis[u] > dis[v] + g[i].cost)
            {
                dis[u] = dis[v] + g[i].cost;
                if(! vis[u])
                {
                    vis[u] = true, que.push(u);
                    num[u]++;
                    if(num[t] > n)
                    {
                        printf("inf\n"); return;
                    }
                    if(num[u] > 2*n)
                    {
                        flag = true; break;
                    }
                }
            }
        }
        if(flag) break;
    }
    printf("%lld\n", -dis[t]);
}
int main()
{
    int n, m, a, b, c;
    scanf("%d%d", &n, &m);
    cnt = 0;
    memset(head, -1, sizeof head);
    for(int i = 1; i <= m; i++)
    {
        scanf("%d%d%d", &a, &b, &c);
        add_edge(a, b, -c);
    }
    spfa(1, n, n);
    return 0;
}

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

int main(void) {
    int Q, T, F, l, r, a, s, i;
    char S[100005], L[200005], R[200005], C;
    scanf("%s%d", S, &Q);
    a=0; l=0; r=0;
    for (i=0; i<Q; i++) {
        scanf("%d", &T);
        if (T==1) {
            a++;
            a%=2;
        }
        else {
            scanf("%d %c", &F, &C);
            if ((a+F)%2==1) {
                L[l]=C;
                l++;
            }
            else {
                R[r]=C;
                r++;
            }
        }
    }
    if (a==0) {
        for (i=0; i<l; i++) printf("%c", L[l-i-1]);
        printf("%s%s", S, R);
    }
    else {
        for (i=0; i<r; i++) {
            printf("%c", R[r-i-1]);
        }
        s=strlen(S);
        for (i=0; i<s; i++) {
            printf("%c", S[s-i-1]);
        }
        printf("%s", L);
    }
    
    /*
    printf("\n");
    printf("%s\n%s\n%s\n", L, S, R);
    printf("%d, %d, %d", a, l, r);
    */
    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> Q;

int mp[35][35][35][35] = { 0 };

int main() {
	int w, h;
	while (cin >> w >> h) {
		if (w == 0 && h == 0) {
			break;
		}
	
		for (int i = 0; i < 35; i++) {
			for (int j = 0; j < 35; j++) {
				for (int k = 0; k < 35; k++) {
					for (int l = 0; l < 35; l++) {
						mp[i][j][k][l] = 0;
					}
				}
			}
		}

		int wall;

		for (int i = 0; i < 2 * h - 1; i++) {
			if (i % 2 == 0) {
				for (int j = 0; j < w - 1; j++) {
					cin >> wall;
					mp[j][i / 2][j + 1][i / 2] = mp[j + 1][i / 2][j][i / 2] = wall;
					//cout << j << ' ' << i / 2 << ' ' << j + 1 << ' ' << i / 2 << endl;
					//cout << i << 'a' << j << endl;
				}
			}
			else {
				for (int j = 0; j < w; j++) {
					cin >> wall;
					mp[j][i / 2][j][(i / 2) + 1] = mp[j][(i / 2) + 1][j][i / 2] = wall;
					//cout << j << ' ' << i / 2 << ' ' << j << ' ' << (i / 2)+1 << endl;
					//cout << i << 'a' << j << endl;
				}
			}
		}
		//cout << 'a' << endl;
		int mpp[35][35] = { 0 };
		queue<Q> q;
		q.push(Q(1, P(0, 0)));
		mpp[0][0] = 1;

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

		int ans = 0;

		//cout << mp[3][2][3][3] << endl;

		while (!q.empty()) {
			bool hh = false;
			Q qq = q.front();
			q.pop();
			P p = qq.second;
			//cout << qq.first << ' '<< p.first << ' ' << p.second << endl;
			for (int i = 0; i < 4; i++) {
				if (0 <= p.first + dx[i] && p.first + dx[i] < w && 0 <= p.second + dy[i] && p.second + dy[i] < h) {
					if (mpp[p.first + dx[i]][p.second + dy[i]] == 0 && mp[p.first][p.second][p.first + dx[i]][p.second + dy[i]] == 0) {
						if (p.first + dx[i] == w - 1 && p.second + dy[i] == h - 1) {
							hh = true;
							ans = qq.first + 1;
							break;
						}
						else {
							//cout << p.first + dx[i] << ' ' << p.second + dy[i] << endl;
							q.push(Q(qq.first + 1, P(p.first + dx[i], p.second + dy[i])));
							mpp[p.first + dx[i]][p.second + dy[i]] = 1;
						}
					}
				}
			}
			if (hh) {
				break;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 8968
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define FOR(i,a,n) for(int i=a,i##_len=(int)n;i<i##_len;++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define SZ(c) ((int)c.size())
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0}, DY[9]={-1,0,1,0,-1,1,1,-1,0};
const int INF=1e9*2; const long long INFLL=1e18*2;
template<class T> ostream& operator << (ostream &os, const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is, vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.second >> p.first; return is; }
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;}
//------------------------------------------------------------------------------

signed main() {
    int H,W;
    cin>>H>>W;
    vector<string> s(H);
    cin>>s;
    REP(i,H) {
        cout<<s[i]<<endl;
        cout<<s[i]<<endl;
    }
    return 0;
}


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

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> d(N);
    for (int i = 0; i < N; i++) {
        cin >> d[i];
    }
    
    for (int i = 0; ; i++) {
        stringstream ss;
        ss << i;
        string s; ss >> s;
        int n = s.size();
        bool found = 0;
        for (int j = 0; j <= N - n; j++) {            
            bool ok = 1;
            for (int k = j; k < j + n; k++) {
                if (d[k] != s[k-j] - '0') {
                    ok = 0;
                    break;
                }
            }
            if (ok) {
                found = 1;
                break;
            }
        }
        if (!found) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 1228
#include <cstdio>

using namespace std;

#define ll long long

int n, k;

int main()
{
    scanf("%d%d", &n, &k);
    ll ans = 0;
    for (ll i = k; i <= n + 1; i++) {
        ll minv = (i * (i - 1LL)) / 2;
        ll maxv = ((ll)(n - i + 1 + n) * i) / 2LL;
        ans += maxv - minv + 1;
        ans %= 1000000007;
    }
    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const int MOD=1e9+7;



int main() {
    ios_base::sync_with_stdio(false); 

    int n;
    cin >> n;
    vector<int> a(n+2);
    rep(i,n) cin >> a[i+1];
    ll d=0;
    rep(i,n+1) d+=abs(a[i]-a[i+1]);
    repr(i,1,n+1) {
        int ans=d-(abs(a[i+1]-a[i])+abs(a[i]-a[i-1])-abs(a[i+1]-a[i-1]));
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<string>

using namespace std;
int main ()
{
	
	string s;
	
	getline(cin,s);
	
	for(int i=0; i<s.length();i++){
		
	if(i==0){
		
		cout<<s[0];
		
	}
		
	if(s[i]==' ')	{
	
	cout<<s[i+1];	
		
		
		
		
	}	
		
		
	}
	
	
	
	
}

Measured memory_bytes: 256
import bisect
n = int(input())
l = list(map(int,input().split()))
l.sort()
cnt = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        a = l[i]+l[j]
        index = bisect.bisect_left(l,a)
        cnt += index - j - 1
print(cnt)

Measured memory_bytes: 3188
/*<<head>> {{{*/
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
//INF = 1 061 109 567 ; INF + INF = 2 122 219 134 ;
//LINF = 4 557 430 888 798 830 399 ; LINF + LINF = 9 114 861 777 597 660 798 ;
const int INF = 0x3f3f3f3f;     // -INF: 0xc0   abs(-INF) = INF + 1
const ll LINF = 0x3f3f3f3f3f3f3f3f;
/*}}}*/                         // zr, zm
const int MOD = (int)1e9+7;     // when MOD = 1e9+7, inv2 = 500000004
const int N = (int)1e5+7;

// ------- 变量 ------- //

int n, a[N];

// ------- 函数 ------- //

void Init() {
    rep(i, 0, n) scanf("%d", a+i);
}

int Solve() {
    db ans = 0;
    priority_queue <db> Q;
    rep(i, 0, n) Q.push(-a[i]);
    while (sz(Q)>1) {
        auto t1 = -Q.top(); Q.pop();
        auto t2 = -Q.top(); Q.pop();
        Q.push((t1 + t2) / -2.0);
    }
    return printf("%.12f\n", -Q.top());
}

// ------- main ------- //

int main ()
{
    //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);

    //Pre();
    //int t; scanf("%d", &t); while (t--) {
    while (~scanf("%d", &n)) {
    //while(fgets(s, N, stdin)) {   // 注意 fgets 会读入换行符
        //if (n == 0) break;
        //static int kase = 0; printf("Case %d: ", ++kase);
        Init();
        Solve();
        //if (t) puts("");
    }
    return 0;
}

Measured memory_bytes: 256
package main

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

const inf = int(1e10)

var ans int

func merge(A []int, left, mid, right int) {
	n1 := mid - left
	n2 := right - mid
	// 前半と後半で要素一つ分大きく確保しておく(番兵用)
	L := make([]int, n1+1) 
	R := make([]int, n2+1)
	for i := 0; i < n1; i++ {
		L[i] = A[left+i]
	}
	for i := 0; i < n2; i++ {
		R[i] = A[mid+i]
	}
	// 番兵をセット
	L[n1] = inf
	R[n2] = inf
	i, j := 0, 0
	for k := left; k < right; k++ {
		ans++
		if L[i] <= R[j] {
			A[k] = L[i]
			i++
		} else {
			A[k] = R[j]
			j++
		}
	}
}
func mergeSort(A []int, left, right int) {
	if left+1 < right {
		mid := left + (right-left)/2
		mergeSort(A, left, mid)
		mergeSort(A, mid, right)
		merge(A, left, mid, right)
	}
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)
	a := make([]int, n)
	for i := range a {
		a[i] = nextInt(sc)
	}
	mergeSort(a, 0, len(a))
	wtr := bufio.NewWriter(os.Stdout)
	for i := 0; i < len(a); i++ {
		if i > 0 {
			fmt.Fprint(wtr, " ")
		}
		fmt.Fprint(wtr, a[i])
	}
	fmt.Fprintln(wtr)
	fmt.Fprintln(wtr, ans)
	wtr.Flush()
}
func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}



Measured memory_bytes: 14864
s = gets.chomp

array = ["Sunny", "Cloudy", "Rainy"]

index = 0
index = array.find_index(s) # find_index で左端から検索

puts array[(index + 1) % 3]
# ( index + 1 )で array 要素を + 1 される
# array[ % 3]で array 要素のうち↑で定義された該当されないものを排除

Measured memory_bytes: 1788
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        long inpt = long.Parse(Reader.ReadLine());

        long ans = (inpt / 11)*2;

        if (inpt % 11 > 6)
        {
            ans+=2;
        }
        else if (inpt % 11 > 0)
        {
            ans++;
        }
        Console.WriteLine(ans);




    }




    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"




149696127901




";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}

Measured memory_bytes: 2648
#include<iostream>
#include<set>

using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll

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

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

signed main() {
    int n;
    cin >> n;
    int a[n];
    rep(i, 0, n) cin >> a[i];
    bool p = 1, s = 1;

    set<int> st;
    rep(i, 0, n) {
        int q = a[i];
        for (int j = 2; j * j <= q; j++) {
            if (q % j == 0) {
                if (*st.find(j) == j) {
                    p = 0;
                    break;
                }
                st.insert(j);
                while (q % j == 0) {
                    q /= j;
                }
            }
        }
        if (q != 1) {
            if (*st.find(q) == q) p = 0;
        }
        st.insert(q);
        if (!p) break;
    }

    // for (auto p : st) cout << p << " ";

    int now = a[0];
    rep(i, 0, n) { now = gcd(now, a[i]); }
    if (now != 1) s = 0;

    if (p) {
        cout << "pairwise coprime\n";
    } else if (s) {
        cout << "setwise coprime\n";
    } else {
        cout << "not coprime\n";
    }
}


Measured memory_bytes: 10908
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) < (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n) - 1; (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;
#define all(x) (x).begin(),(x).end()

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll fac(ll n){
    ll t = 1;
    rep1(i, n + 1)t *= i;
    return t;
}

int main()
{
    ll x,ans;
    cin >> x;
    ans = x/11;
    ans *= 2;
    if (x % 11 > 0 && x % 11 <= 6) {
        ++ans;
    }else if(x % 11 > 6){
        ans += 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m=0;//a[i]の最大値;
    cin>>n;
    int a[n];
    vector<long long>x;//要素a[i]とおなじものの個数
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]>m){
            m=a[i];
            x.resize(m);
        }
        x[a[i]-1]++;
    }
    long long allc=0;//ボールを取り除かない場合の全ての選び方
    for(int i=0;i<m;i++)allc+=x[i]*(x[i]-1)/2;
    for(int i=0;i<n;i++)cout<<allc-x[a[i]-1]+1<<endl;
    return 0;
}

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};
const int MOD = 1000000007;


int N, M;
int a[1001], b, c[1001];
ll dp[1001][4096];

ll solve(){
    int K = 1 << N;
    REP(i, M + 1) REP(j, K) dp[i][j] = INT32_MAX;
    dp[0][0] = 0;
    REP(i, M){
        REP(j, K){
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
            dp[i + 1][j | c[i]] = min(dp[i + 1][j | c[i]], dp[i][j] + a[i]);
        }
    }
    if(dp[M][K - 1] >= INT32_MAX) return -1;
    return dp[M][K - 1];  
}

signed main(){
    cin >> N >> M;
    REP(i, M){
        cin >> a[i] >> b;
        int id;
        REP(j, b){
            cin >> id;
            c[i] += 1 << (id - 1);
        }
    }
    PRINT(solve());
    return 0;
}

Measured memory_bytes: 32256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <stack>
#include <cstring>
#include <cassert>

#include <atcoder/maxflow>

using namespace std;

#ifdef LOCAL_DEBUG
#include <local_debug.h>
#define DEBUG(...) DBG2::print(#__VA_ARGS__, __LINE__, __VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;

#define NODE_ID(r, c) ((r)*C + (c))

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(nullptr);

   int R, C;
   cin >> R >> C;
   vector<string> B(R);
   REP(r, R)
      cin >> B[r];

   atcoder::mf_graph<int> mf(R*C + 2);
   const int SRC = R*C;
   const int SINK = R*C+1;
   REP(r, R) {
      REP(c, C) {
         if (B[r][c] != '.') continue;
         int u = NODE_ID(r, c);
         if ((r+c) & 1)
            mf.add_edge(u, SINK, 1);
         else
            mf.add_edge(SRC, u, 1);
      }
   }

   REP(r, R) {
      REP(c, C) {
         if (B[r][c] != '.') continue;
         int u = NODE_ID(r, c);
         if (r > 0 && B[r-1][c] == '.') {
            int v = NODE_ID(r-1, c);
            if ((r+c) & 1)
               mf.add_edge(v, u, 1);
            else
               mf.add_edge(u, v, 1);
         }
         if (c > 0 && B[r][c-1] == '.') {
            int v = NODE_ID(r, c-1);
            if ((r+c) & 1)
               mf.add_edge(v, u, 1);
            else
               mf.add_edge(u, v, 1);
         }
      }
   }

   int res = mf.flow(SRC, SINK);
   cout << res << '\n';

   for (auto e : mf.edges()) {
      if (e.from == SRC || e.to == SINK)
         continue;
      if (e.flow) {
         int r1 = e.from / C, c1 = e.from % C;
         int r2 = e.to / C, c2 = e.to % C;
         if (r1 == r2) {
            assert(c1 != c2);
            B[r1][min(c1,c2)] = '>';
            B[r1][max(c1,c2)] = '<';
         }
         else {
            assert(c1 == c2);
            B[min(r1,r2)][c1] = 'v';
            B[max(r1,r2)][c1] = '^';
         }
      }
   }

   for (string line : B)
      cout << line << '\n';

   return 0;
}


Measured memory_bytes: 5552
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
INF = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    X, K, D = il()
    max_dist = K * D
    if max_dist > abs(X):
        c = abs(X) // D
        k = K - c
        if k % 2 == 0:
            print(abs(abs(X) - (c * D)))
        else:
            print(min(abs(abs(X) - (c * D) + D), abs(abs(X) - (c * D) - D)))
    else:
        print(abs(abs(X) - max_dist))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9900
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MOD 1000000007
#define MAX 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ub upper_bound
#define lb lower_bound
#define zoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

void solve(vector<vector<ll> >& ans, ll strt, ll base, ll en, ll prev, ll curr) {
	ll i, j;
	for(i = base - prev; i <= base; i += 1) {
		for(j = strt; j <= en; j += 1) 
			ans[i][j] = curr;
	}
}

int main() {

    zoom;
    ll H, W, K, i, j;
    cin >> H >> W >> K;
    vector<vector<ll> > ans(H, vector<ll>(W, 0));
    ll prev = 0, curr = 1;
    for(i = 0; i < H; i += 1) {
    	string s;
    	cin >> s;
    	bool done = false;
    	ll strt = 0;
    	for(j = 0; j < W; j += 1) {
    		if(s[j] == '.')
    			continue;
    		done = true;
    		solve(ans, strt, i, j, prev, curr);
    		strt = j + 1;
    		curr += 1;
    	}
    	if(done)
    		prev = 0;
    	else
    		prev += 1;
    }
    for(i = 0; i < H; i += 1) {
    	for(j = 0; j < W; j += 1) {
    		if((ans[i][j] == 0) && (j != 0))
    			ans[i][j] = ans[i][j - 1];
    	}
    }
    for(j = 0; j < W; j += 1) {
    	for(i = 0; i < H; i += 1) {
    		if((ans[i][j] == 0) && (i != 0))
    			ans[i][j] = ans[i - 1][j];
    	}
    }
    for(i = 0; i < H; i += 1) {
    	for(j = 0; j < W; j += 1)
    		cout << ans[i][j] << " ";
    	cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1536
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
int n,m,x,y,a[1111],b[1111],col[1111],cnt1,cnt2,cnt,ans;
vector<int> g[1111];
bool mp[1111][1111],f,dp[1111][1111];
void dfs(int i,int co)
{
	col[i]=co;
	if (co==1) cnt1++;
	else cnt2++;
	for (int j=0;j<g[i].size();j++)
	{
		int to=g[i][j];
		if (col[to]==co) 
		{
			f=1;
			continue;
		}
		else if (col[to]) continue;
		dfs(to,3-co);
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++)
	{
		scanf("%d%d",&x,&y);
		mp[x][y]=mp[y][x]=1;
	}
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=n;j++)
		{
			if (i==j) continue;
			if (!mp[i][j]) g[i].push_back(j); 
		}
	}
	for (int i=1;i<=n;i++)
	{
		if (!col[i]) 
		{
			cnt1=cnt2=0;
			dfs(i,1);
			if (f)
			{
				printf("-1\n");
				return 0;
			}
			a[++cnt]=cnt1;b[cnt]=cnt2;
		}
	}
	dp[0][0]=1;
	for (int i=1;i<=cnt;i++)
	{
		for (int j=1;j<=n;j++)
		{
			if (j>=a[i]) dp[i][j]|=dp[i-1][j-a[i]];
			if (j>=b[i]) dp[i][j]|=dp[i-1][j-b[i]];
		}
	}
	ans=1e9;
	for (int i=1;i<=n;i++)
	{
		if (dp[cnt][i]) 
		{
			ans=min(ans,i*(i-1)/2+(n-i)*(n-i-1)/2);
		}
	}
	printf("%d\n",ans);
	return 0;
} 

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

#define fr first
#define sc second
#define OK puts("OK");
#define pb push_back
#define mk make_pair

using namespace std;

typedef long long ll;

const int inf = (int)1e9 + 7;
const int N = (int)1e5 + 7;

ll n,res = 1;
int len;
int c;

int sz (ll x) {
    int cnt = 0;

    while (x > 0) {
        c = x;
        x /= 10;
        cnt ++;
    }
    return cnt;
}
int main () {
    cin >> n;

    len = sz(n);

    for (int i = 1; i < len; i ++)
        res *= 10;

    if ((n + 1) == (c + 1) * 1ll * res)
        cout << (len - 1) * 1ll * 9 + c << endl;
    else
        cout << (len - 1) * 9 + (c - 1) << endl;
}


Measured memory_bytes: 256
string = list(str(input()).split(' '))
l = [0]*len(string)
k = 0
r = 0
for i in range(len(string)):
    if len(string[i]) > k:
        k = len(string[i])
        r = i
    for j in range(len(string)):
        if string[i] == string[j]:
            l[i] += 1
m = l.index(max(l))
print(string[m],string[r],sep = ' ')

Measured memory_bytes: 7396
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class A
{
	public static void Main()
	{
		int N = GetInt();
		int[] A = Enumerable.Repeat(1, N).Select(_ => GetInt()).ToArray();
		int ans = 1;
		int mode = 0;
		for(int i = 1; i < N; i++)
		{
			switch(A[i].CompareTo(A[i-1]))
			{
				case 0:
					break;

				case 1:
					if(mode == -1)
					{
						mode = 0;
						ans++;
					}
					else
					{
						mode = 1;
					}
					break;

				case -1:
					if(mode == 1)
					{
						mode = 0;
						ans++;
					}
					else
					{
						mode = -1;
					}
					break;
			}
		}

		Console.WriteLine(ans);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}

Measured memory_bytes: 25568
#include<iostream>
using namespace std;
int main()
{
	int n; cin>>n;
	int a=1000,v=0;
	for(int i = 0; i < n; ++i)
	{
		int aa,vv;
		cin>>aa>>vv;
		if(v<vv)
		{
			a=aa; v=vv;
		}
		else
		{
			if(v==vv&&aa<a)
			{
				a=aa;
			}
		}
	}
	cout<<a<<" "<<v<<endl;
  return 0;
}

Measured memory_bytes: 1168
import std.stdio, std.conv, std.string, std.algorithm,
       std.math, std.array, std.container, std.typecons;

void main() {
  auto n = readln.chomp.to!int;
  auto p = readln.chomp.split.to!(int[]);
  int count=0, minimum=n+1;
  for(int i=0; i<n; i++) {
    if(p[i]<=minimum) {
      count++;
      minimum = min(minimum, p[i]);
    }
  }
  writeln(count);
}



Measured memory_bytes: 11408
#include <stdio.h>

int main(void)
{
	//aとbは入力値
	int a,b;

	//scanf関数でデータを取得
	scanf("%d %d",&a, &b);

	//aがbより大きければ "a > b" と出力
	if(a > b){
		printf("a > b\n");
	}//aとbが等しければ "a == b" と出力
	else if(a == b){
		printf("a == b\n");
	}//aがbより小さければ "a < b" と出力
	else{
		printf("a < b\n");
	}

	return 0;
}


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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef long double LD;
typedef pair<LD, LD> PLDLD;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
#define ALL(a) a.begin(),a.end()

LL norm(LL p,LL q)
{
	return (p+ -(p/q-1)*q)%q;
}

int main()
{
	LL n;
	cin>>n;
	vector<LL> a(n+1);
	LL sum=0;
	REP(i,n) cin>>a[i];
	a[n]=a[0];
	REP(i,n) sum+=a[i];
	LL num=sum/((1+n)*n/2);

	if(num*((1+n)*n/2)!=sum)
	{
		cout<<"NO"<<endl;
		return 0;
	}

	bool flag=1;
	REP(i,n)
	{
		LL dis=a[i+1]-a[i];
		if(norm(dis,n) != num%n || dis>num)
		{
			//cout<<num<<dis<<i<<endl;
			flag=0;
			break;
		}
	}

	if(flag)
		cout<<"YES"<<endl;
		else
		cout<<"NO"<<endl;

}


Measured memory_bytes: 1152
#!/usr/bin/env python
# coding: utf-8

import queue

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

dx = [0, 1, 0, -1]
dy = [-1, 0, 1, 0]

class BFS:
    def __init__(self, h, w, board):
        self.h = h
        self.w = w
        self.board = board
        self.num_empty = 0
        for x in range(1, w+1):
            for y in range(1, h+1):
                if self.board[y][x] == '.':
                    self.num_empty += 1
        self.cost = [[-1 for _ in range(w+2)] for _ in range(h+2)]

    def search(self):
        q = queue.Queue()
        q.put((1, 1))
        self.cost[1][1] = 1
        while not q.empty():
            p = q.get()
            x, y = p[0], p[1]
            for i in range(4):
                nx = x+dx[i]
                ny = y+dy[i]
                if self.board[ny][nx] == '#':
                    continue
                if self.cost[ny][nx] >= 0:
                    continue
                q.put((nx, ny))
                self.cost[ny][nx] = self.cost[y][x]+1
        c = self.cost[self.h][self.w]
        if c == -1:
            return -1
        else:
            return self.num_empty - c

def main():
    h, w = rli()
    board = []
    board.append('#'*(w+2))
    for _ in range(h):
        board.append('#'+input()+'#')
    board.append('#'*(w+2))
    bfs = BFS(h, w, board)
    ans = bfs.search()
    print(ans)



if __name__ == '__main__':
    main()


Measured memory_bytes: 4080
import numpy as np
n,C = map(int,input().split())
ch = [[] for _ in range(30)]
for _ in range(n):
    s,t,c = map(int,input().split())
    if s>t:
        s,t = t,s
    ch[c-1].append((s,t))

lst = []
for i in range(30):
    if len(ch[i])!=0:    
        for i, (ns,nt) in enumerate(ch[i]):
            if i==0:
                s,t = ns, nt
            else:
                if ns == t:
                    t = nt
                else:
                    lst.append((s,t))
                    s,t = ns, nt
        else:
            lst.append((s,t))
    
d = [0]*(10**6)
for s,t in lst:
    d[s-1] += 1
    d[t] -= 1
d = np.cumsum(d)
print(min(max(d), C))

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

int main() {
  string S ; 
  cin >> S ; 
  int Q ; 
  cin >> Q ; 
  deque<char> q ; 
  
  for(char c : S) q.push_back(c) ; 
  
  int A = 1 ; 
  for(int i = 0 ; i < Q ; i++){
    int T ;  cin >> T ;  
    if(T == 1){
      A = (A + 1)%2 ;
    }
    if(T != 1){
      int F ; cin >> F ; 
      
      if(F == 1){
        if(A == 1){
        	char C ; 
        	cin >> C ;
        	q.push_front(C) ; 
        }
        else{
            char C ; 
            cin >> C ;
            q.push_back(C) ; 
        }
      }
      else{
        if(A == 1){
        	char C ; 
        	cin >> C ;
            q.push_back(C) ; 
        }
        else{
            char C ; 
            cin >> C ;
            q.push_front(C) ; 
        }         
      }
    }
  }
  
  if(A == 0){
    reverse(q.begin(),q.end());
  }

  string ans ; 
  for(char c : q) ans += c ; 
  cout << ans << endl;
  

  
}

Measured memory_bytes: 4216
from itertools import (
    accumulate,  # 累積和のイテレータ
    groupby,  # 値をkey,同じ値の集まりをgroup
    permutations,  # 順列
    combinations,  # 組み合わせ
    product,  # 重複あり順列（直積, 深いネストにも使える）
    combinations_with_replacement,  # 重複あり組み合わせ
)

N, M, Q = map(int, input().split())
q = []
for _ in range(Q):
    q.append(list(map(int, input().split())))

ans = 0
for v in combinations_with_replacement(range(1, M+1), N):
    score = 0
    for i in range(Q):
        joken = q[i]
        if v[joken[1]-1] - v[joken[0]-1] == joken[2]:
            score += joken[3]
    ans = max(ans, score)
    #print(v, ': ', score)

print(ans)

Measured memory_bytes: 67996
(* メモテーブル *)
let memo_table = Array.make 100 None

let rec lucas n =
  match memo_table.(n + 1) with
    Some (v) -> v
  | None ->
    let result = 
    	if n = 0 then 2 else if n = 1 then 1
        else lucas(n - 1) + lucas(n - 2) in
    (memo_table.(n + 1) <- Some result;
     result)
     
(* メイン関数 *)     
let go () =
	let v = read_line() in
    let result = lucas (int_of_string v) in
    print_int result
    
let _ = go()

Measured memory_bytes: 3700
x,y=map(int,input().split())
ans=0
if x==3:
  ans+=100000
elif x==2:
  ans+=200000
elif x==1:
  ans+=300000
if y==3:
  ans+=100000
elif y==2:
  ans+=200000
elif y==1:
  ans+=300000
if x==1 and y==1:
  ans+=400000
print(ans)

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> point;
#define F first
#define S second

struct treap
{
	struct node
	{
		node *ch[2];
		ll key, lazy, m;
		int prio, sz;

		node(ll key) : key(key), m(key)
		{
			ch[0] = ch[1] = NULL;
			lazy = 0;
			sz = 1;
			prio = rand();
		}
	}*root;

	node* new_node(ll key)
	{
		return new node(key);
	}

	int size(node *u)
	{
		return u ? u->sz : 0;
	}

	ll getM(node *u)
	{
		return u ? u->m : numeric_limits<ll>::max();
	}

	void push(node *u)
	{
		if(!u)
			return;

		if (u->lazy != 0)
		{
			u->key += u->lazy;
			u->m += u->lazy;
			for (int i = 0; i < 2; ++i)
				if (u->ch[i])
					u->ch[i]->lazy += u->lazy;
			u->lazy = 0;
		}
	}

	node* update(node *u)
	{
		if (u)
		{
			u->sz = size(u->ch[0]) + size(u->ch[1]) + 1;
			push(u), push(u->ch[0]), push(u->ch[1]);
			u->m = min({ u->key, getM(u->ch[0]), getM(u->ch[1]) });
		}
		return u;
	}

	pair<node*, node*> split(node* u, int k)
	{// split for the kth first elements
		push(u);

		if (!u)
			return { u, u };

		if (size(u->ch[0]) >= k)
		{
			auto s = split(u->ch[0], k);
			u->ch[0] = s.second;
			return { s.first, update(u) };
		}

		auto s = split(u->ch[1], k - size(u->ch[0]) - 1);
		u->ch[1] = s.first;
		return { update(u), s.second };
	}

	node* merge(node *u, node *v)
	{
		push(u), push(v);

		if (!u || !v)
			return u ? u : v;

		if (u->prio > v->prio)
		{
			u->ch[1] = merge(u->ch[1], v);
			return update(u);
		}

		v->ch[0] = merge(u, v->ch[0]);
		return update(v);
	}

	treap() : root(NULL) {}
};

int main()
{
	#ifdef DGC
		freopen("a.txt", "r", stdin);
		//freopen("out.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(0), cin.tie(0);

	srand(time(0));
	int n, m;
	cin >> n >> m;

	ll ans = 0;
	vector<vector<pair<int, int>>> c(n+1);
	for (int i = 0, a, b, w; i < m; ++i)
	{
		cin >> a >> b >> w;
		c[b].push_back({ a, w });
		ans += w;
	}

	treap t;
	t.root = t.merge(t.root, t.new_node(0));

	for (int i = 1; i <= n; ++i)
	{
		t.root = t.merge(t.new_node(t.root->m), t.root);

		for (auto k : c[i])
		{
			auto p = t.split(t.root, i-k.F+1);
			p.S->lazy += k.S;
			t.root = t.merge(p.F, p.S);
		}
	}

	cout << ans-t.root->m << "\n";

	return 0;
}



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

int main(){
  int n,m,x;
  int money;
  int ans=-1;
  cin >>n>>m>>x;
  vector<int>c(n);
  vector<int>skill(m);
  vector<vector<int>>a(n,vector<int>(m));
  for(int i=0;i<n;i++){
    cin >>c.at(i);
    for(int j=0;j<m;j++)
      cin >>a.at(i).at(j);
  }
  for(int bit=0;bit<(1<<n);bit++){
    for(int i=0;i<m;i++){
      skill.at(i)=0;
    }
    money=0;
    for(int j=0;j<n;j++){
      if(bit>>j&1){
        money+=c.at(j);
        for(int k=0;k<m;k++){
          skill.at(k)+=a.at(j).at(k);
        }
      }
    }
    sort(skill.begin(),skill.end());
    if(skill.at(0)>=x){
      if(ans==-1)ans=money;
      else ans=min(ans,money);
    }
  }
  cout <<ans<<endl;
}

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

int main()
{
    int n,k;
    cin >> n >> k;
    int arr[n] = {0};
    for(int i=0;i<k;i++){
        int d;
        cin >> d;
        while(d--){
            int k;
            cin >> k;
            arr[k-1]++;
        }
    }
    int c = 0;
    for(int i=0;i<n;i++){
        if(arr[i] == 0){
            c++;
        }
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while (sc.hasNextInt()) {
            int H = sc.nextInt();
            int W = sc.nextInt();
            char[][] t = new char[H][W];
            for (int i = 0; i < H; i++) {
                t[i] = sc.next().toCharArray();
            }
            for (int i = 0; i < H * 2; i++) {
                for (int j = 0; j < W; j++) {
                    System.out.print(t[i / 2][j]);
                }
                System.out.println();
            }
        }
    }
}


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

#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define si set<int>
#define sl set<long long>
#define pq prioirty_queue
#define all(v) v.begin(),v.end()
#define left (2*idx)+1
#define right (2*idx)+2
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);

const ll N = (ll)(2e5 + 7);
const ll MOD = (ll)(1e9 + 7);

vector<long long> v(N, 0);
vector<int> adj[N];

void dfs1(int i, int P)
{
    v[i]+=v[P];

    for(auto j : adj[i])
    {
        if(j == P)
        {
            continue;
        }
        dfs1(j, i);
    }

}
int main()
{
    FIO;
    
    int n, m, q;
    cin >> n >> q;

    m = n-1;
    while(m--)
    {
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }

    while(q--)
    {
        ll p, x;
        cin >> p >> x;
        v[p]+=x;
    }

    dfs1(1, 0);
    for(int i=1; i<=n; i++)
        cout << v[i] << " ";

}


Measured memory_bytes: 24320
//by Top1
#include <bits/stdc++.h>
          
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define pll pair <long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define cerr cout
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return 
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x * x 
      
const int inf = (1e18) + 1;
const int mod = 479001599;
const int maxn = 5e5 + 111;
        
using namespace std;          

int n, pref[maxn][5], b[30];
string s;

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

	b['R' - 'A'] = 1;
	b['G' - 'A'] = 2;
	b['B' - 'A'] = 3;

    for (int i = 0; i < n; i++){
    	pref[i][1] = pref[i - 1][1];
    	pref[i][2] = pref[i - 1][2];
    	pref[i][3] = pref[i - 1][3];
    	if (s[i] == 'R')
    		pref[i][1]++;
    	else if (s[i] == 'G')
    		pref[i][2]++;
    	else 
    		pref[i][3]++;
    }

    int ans = 0;

    for (int i = 0; i < n; i++){
    	for (int k = i + 3; k < n; k++){
    		if (s[i] != s[k]){
    			int pos = 6 - b[s[i] - 'A'] - b[s[k] - 'A'];
    			int x = pref[k][pos] - pref[i][pos];
    			if ((i + k) % 2 == 0 && b[s[(i + k) >> 1] - 'A'] == pos)
    				x--;
    			ans += x;
    		}
    	}
    }

    cout << ans;                               
}                              
      
main(){
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

    boost;
    
    int q = 1;
 
    //cin >> q;
    
    while (q--){
        solve();
    }
}

Measured memory_bytes: 3780
import java.util.*;
public class Main 
{
	public static int gcd(int a, int b)
	{
		if(a % b == 0)
		{
			return(b);
		}
		return(gcd(b, a % b));
	}
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext())
		{
			int a = stdIn.nextInt();
			int b = stdIn.nextInt();
			if(a < b)
			{
				int temp = a;
				a = b;
				b = temp;
			}
			System.out.println(gcd(a, b));
		}
	}
}

Measured memory_bytes: 12000
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpT, *szpFpA;
#endif

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	int i;
	char lc1Buf[1024], lc1Out[1024];

	// テストファイルオープン
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpT = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#endif

	// 取得
	int liD, liN;
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif
	sscanf(lc1Buf, "%d%d", &liD, &liN);

	// 100の場合
	if (liN == 100) {
		liN = 101;
	}

	// 100倍
	for (i = 0; i < liD; i++) {
		liN *= 100;
	}

	// 結果セット
	sprintf(lc1Out, "%d\n", liN);

	// 結果表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpT);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



Measured memory_bytes: 128
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int N;
int main(){
	cin>>N;
	int a,b;
	a=N/100;
	b=N%10;
	if(a==b)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}


Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	a, b, c, d, e, f := nextInt(), nextInt(), nextInt(), nextInt(), nextInt(), nextInt()

	max, water, sugar := 0.0, 100*a, 0
	for i := 0; i <= 30; i++ {
		for j := 0; j <= 30; j++ {
			for k := 0; k <= 100; k++ {
				for l := 0; l <= 100; l++ {
					w, s := 100*(a*i+b*j), c*k+d*l
					if w+s > f || (w/100)*e < s {
						continue
					}
					if x := float64(100*s) / float64(w+s); x > max {
						max = x
						water, sugar = w, s
					}
				}
			}
		}
	}

	puts(water+sugar, sugar)
}


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

int main() {
  int N, M, C;
  cin >> N >> M >> C;
  vector<int> B(M);
  for (int i = 0; i < M; i++)
  {
    cin >> B[i];
  }
  int ans = 0;
  for (int i = 0; i < N; i++)
  {
    int temp = C;
    for (int j = 0; j < M; j++)
    {
      int A;
      cin >> A;
      temp += A * B[j];
    }
    if (temp > 0)
    {
      ans++;
    }
    
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3624
import java.util.Arrays;
import java.util.Scanner;

/**
 * Created by Harry on 3/30/20.
 */
//https://atcoder.jp/contests/dp/tasks/dp_e
public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int w = scanner.nextInt();
        int[] weights = new int[n];
        int[] values = new int[n];
        for(int i=0; i<n; i++){
            weights[i] = scanner.nextInt();
            values[i] = scanner.nextInt();
        }
        System.out.println(findMaxValue(weights ,values, n, w));
    }

    public static int findMaxValue(int[] weights, int[] values, int n, int w){
        int valSum = 0;
        for(int val : values){
            valSum += val;
        }
        int res = 0;
        long[] dp = new long[valSum+1];
        Arrays.fill(dp, (long)1e13);
        dp[0] = 0;
        for(int i=1; i<=n; i++){
            for(int val=valSum; val>=values[i-1]; val--){
                dp[val] = Math.min(dp[val], dp[val-values[i-1]]+weights[i-1]);
                if(dp[val]<=w){
                    res = Math.max(res, val);
                }
            }
        }

        return res;
    }
}


Measured memory_bytes: 25428
N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

xmax = max(x)
ymin = min(y)
for i in range(X+1, Y+1):
  if xmax < i <= ymin:
    print("No War")
    exit()
print("War")

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

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

int N, M;
bool G[21][21];

int main() {
  while (cin >> N >> M) {
	memset(G, 0, sizeof(G));
	for (int i = 0; i < M; ++i) {
	  int a, b;
	  cin >> a >> b;
	  --a, --b;
	  G[a][b] = G[b][a] = true;
	}

	int res = 0;
	vector<int> ord;
	for (int i = 0; i < N; ++i) ord.push_back(i);
	do {
	  if (ord[0] != 0) continue;
	  bool ok = true;
	  for (int i = 0; i + 1 < ord.size(); ++i) {
		if (!G[ord[i]][ord[i+1]]) ok = false;
	  }
	  if (ok) ++res;
	} while (next_permutation(ord.begin(), ord.end()));

	cout << res << endl;
  }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX(a,b,c) max(a,max(b,c))
#define MIN(a,b,c) min(a,min(b,c))

int main()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	
	if(s.size()<=n)
		cout<<s<< endl;
	else
	{
		for(int i=0; i<n; i++)
			cout<<s[i];
		
		cout<<"..."<< endl;
	}
	
	return 0;
}


Measured memory_bytes: 3628