akhauriyash/Code-Regression huggingface dataset:
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <functional>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define	BitSetV(Val,Bit)		((Val) |= (Bit))			
#define	BitTstV(Val,Bit)		((Val) & (Bit))				
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define	MIN_QWORD				((QWORD)0x0000000000000000)
#define	MAX_SQWORD				((SQWORD)0x7FFFFFFFFFFFFFFF)
#define	MIN_SQWORD				((SQWORD)0x8000000000000000)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long			DWORD;
typedef unsigned long long int	QWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
/* 素因数分解 */
map<ll, ll> factMap;
void primeFactor(ll n)
{
    if ((n % 2) == 0){
        while((n % 2) == 0) {
            factMap[2]++;
            n = n / 2;
        }
    }

    for(ll i = 3; i <= sqrt(n); i += 2){
        while ((n % i) == 0){
            factMap[i]++;
            n = n / i;
        }
    }

	if (n != 1) {
		factMap[n]++;
	}
}


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

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

// メイン
int main()
{
	// 入力
	ll N, M;
	cin >> N >> M;

	// 素因数分解
	primeFactor(M);

	// コンビネーション
	// 各素数をN分割した結果(n+k-1Ck)の組み合わせ(乗算)
	ll ans = 1;
	CombInit();
	for (auto one : factMap) {
		ans *= CombExec(N + one.second - 1, one.second);
		ans %= MOD;
	}

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



Measured memory_bytes: 47104
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        int d = a / b;
        int r = a % b;
        double f;
        
        System.out.printf(d + " " + r + " ");
        System.out.printf("%.9f",(double)a/(double)b);
    }
}


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

const int N = 160;

typedef long long LL;

int mod;

inline void Inc(int &x, int y) {
    x += y, x -= x >= mod ? mod : 0;
}

inline int solve1(int n, int k) {
    static int f[N]; memset(f, 0, sizeof(f)), f[0] = 1;
    for (int i = 1; i <= n + 1; i++)
        for (int j = 0; j <= k && i - 1 - j >= 0; j++) 
            Inc(f[i], f[i - 1 - j]);
    return f[n + 1];
}

int dp[N][N][N], type[N];

inline int solve2(int n, int k) {
    int tot = 0;
    for (int i = 1; i * 2 - k <= n; i++) {
        int a = i * 2, b = i * 2 - k; tot++;
        if (a <= n) type[tot] |= 2;
        if (b > 0) type[tot] |= 1; 
    }
    dp[0][0][0] = 1;
    for (int i = 1; i <= tot; i++) 
        for (int j = 0; j <= i * 2 && j <= k + 1; j++)
            for (int k = 0; k <= i; k++) if (dp[i - 1][j][k]) {
                Inc(dp[i][0][0], dp[i - 1][j][k]);
                if (type[i] & 1) Inc(dp[i][j ? j + 1 : 0][0], dp[i - 1][j][k]);
                if (type[i] & 2) Inc(dp[i][0][k + 1], dp[i - 1][j][k]);
                if (type[i] == 3) Inc(dp[i][j ? j + 1 : k + 2][k + 1], dp[i - 1][j][k]);
            }
    int res = 0;
    for (int j = 0; j <= k + 1; j++)
        for (int k = 0; k <= tot; k++) Inc(res, dp[tot][j][k]);
    return res;
}

int main() {
    int n, k; scanf("%d%d%d", &n, &k, &mod);
    if (k % 2 == 0) printf("%d\n", ((LL)solve1(n / 2, k / 2) * solve1((n + 1) / 2, k / 2)) % mod);
    else if (k == 1) printf("%d\n", solve1(n, 2));
    else printf("%d\n", solve2(n, k));
}

Measured memory_bytes: 7980
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }

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

  ll n, k;
  cin >> n >> k;
  vector<ll> d(k);
  rep(i, 0, k) cin >> d[i];

  for(ll i = n; i <= n*10; i++){
    ll num = i;
    set<ll> s;
    while(num){
      s.insert(num%10);
      num /= 10;
    }

    bool ok = true;
    for(ll i = 0; i < k; i++){
      if(s.count(d[i]) > 0) ok = false;
    }
    if(ok){
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}

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

struct v{
	long long a;
	long long b;
	int na;
};

int compare_int(const void *a,const void *b){
	if(*(long long*)a>*(long long*)b)return 1;
	return -1;
}
int compare_intt(const void *a,const void *b){
	struct v A=*(struct v*)a,B=*(struct v*)b;
	if(A.b>B.b)return 1;
	else if(A.b==B.b){
		if(A.a>B.a)return 1;
	}return -1;
}

int main(){
	int n,i;
	struct v b[100000];
	long long acp[100000];
	scanf("%d",&n);
	for(i=0;i<100000;i++)acp[i]=2000000000;
	for(i=0;i<n;i++)scanf("%lld",&b[i].a),acp[i]=b[i].a;
	for(i=0;i<n;i++)scanf("%lld",&b[i].b);
	qsort(acp,n,sizeof(long long),compare_int);
	for(i=0;i<n;i++){
		long long am=b[i].a;
		int r=n,l=-1;
		while(r-l>1){
			int mid=(r+l)/2;
			if(acp[mid]>=am)r=mid;
			else l=mid;
		}
		b[i].na=r;
	}
	qsort(b,n,sizeof(b[0]),compare_intt);
	for(i=0;i<n;i++){
		if(acp[i]>b[i].b){
			puts("No");
			return 0;
		}
	}
	for(i=0;i<n-1;i++){
		if(acp[i+1]<=b[i].b){
			puts("Yes");
			return 0;
		}
	}
	int c=0,co=0;
	while(1){
		c=b[c].na;
		if(c==0)break;
		co++;
	}
	if(co<n-1)puts("Yes");
	else puts("No");
	return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);

  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  rep(i, n) cin >> v[i];

  int ans = 0;
  int min_pop = min(n, k);
  for (int i = 0; i <= min_pop; ++i) {
    int throw_away = k - i;
    for (int a = 0; a <= i; ++a) {
      int b = i - a;
      vector<int> temp;
      rep(j, a) temp.push_back(v[j]);
      rep(j, b) temp.push_back(v[n - 1 - j]);
      sort(temp.begin(), temp.end());
      int sum = accumulate(temp.begin(), temp.end(), 0);
      int loop_max = min(throw_away, (int)temp.size());
      rep(j, loop_max) {
        if (temp[j] < 0) sum += -temp[j];
      }
      ans = max(ans, sum);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc095/tasks/arc096_a

#include <algorithm>
#include <cmath>
#include <iostream>
#include <regex>
#include <set>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

#define EPS (1e-7)
#define INF (1e9)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

// long gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// long lcm(long a, long b) { return a * b / gcd(a, b); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c, x, y, ans;
    cin >> a >> b >> c >> x >> y;
    // Cセットが高ければ、別々に買う
    if (a + b < 2 * c) {
        ans = a * x + b * y;
    } else {
        if (x > y) {
            ans = (x - y) * a + 2 * c * y;
        } else {
            ans = (y - x) * b + 2 * c * x;
        }
        int ans2 = max(x, y) * 2 * c;
        ans = min(ans, ans2);
    }
    cout << ans << endl;

    return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    vector<int> b(N);
    vector<int> c(N);
    rep(i,N){
        cin >> a[i] >> b[i] >> c[i];
    }
    int dp[3]   = {};
    int next[3] = {};

    rep(i, N) {
        next[0] = max(dp[1], dp[2]) + a[i];
        next[1] = max(dp[0], dp[2]) + b[i];
        next[2] = max(dp[0], dp[1]) + c[i];
        dp[0] = next[0];
        dp[1] = next[1];
        dp[2] = next[2];
    }
    cout << max({dp[0],dp[1],dp[2]}) << endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define r(i,n) for(int i=1;i<n;i++)
using namespace std;
string s,t[]={"","',.!?","abcABC","defDEF","ghiGHI","jklJKL","mnoMNO","pqrsPQRS","tuvTUV","wxyzWXYZ"};
main(){
  while(cin>>s){
    int pre=s[0],c=0;
    r(i,s.size()){
      if(s[i]==pre&&pre!='0')c++;
      else if(s[i]==pre)cout<<' ';
      else{
        if(pre!='0')cout<<t[pre-'0'][c%t[pre-'0'].size()];
        c=0;
        pre=s[i];
      }
      if(i==s.size()-1)cout<<t[pre-'0'][c%t[pre-'0'].size()];
    }
    cout<<endl;
  }
}

Measured memory_bytes: 3164
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int N;
long long a[100010][3];

long long dp[100010][3];

int main(){
  int N; cin >> N;
  for(int i = 0; i < N; i++) for(int j = 0; j < 3; j++) cin >> a[i][j];
  
  for(int i = 0; i < N; i++){
    for(int j = 0; j < 3; j++){
      for(int k = 0; k < 3; k++){
        if(j == k) continue;
        chmax(dp[i + 1][k], dp[i][j] + a[i][k]);
      }
    }
  }
  long long res = 0;
  for(int j = 0; j < 3; j++) chmax(res, dp[N][j]);
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 8256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {

			StringBuffer sb = new StringBuffer(br.readLine());
			System.out.println(sb.reverse().toString());

		} finally {
			br.close();
		}

	}

}

Measured memory_bytes: 16856
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        a: usize,
        b: usize,
        c: usize,
        d: usize,
    }
    println!("{}", max(a*b, c*d));
}


Measured memory_bytes: 2172
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <string>
#include <cstring>
#include <complex>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

const int N = 100100;
int n;
ll a[N], b[N];

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%lld%lld", &a[i], &b[i]);

    ll ans = 0;
    for (int i = n - 1; i >= 0; i--)
    {
        ll x = a[i] + ans;
        ll y = (b[i] - (x % b[i])) % b[i];
        ans += y;
    }
    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <iostream>

using namespace std;

typedef long long ll;
typedef double db;

#define dbg(x) cout<<#x<<" is "<<x<<endl

int main() {
    int x;
    cin >> x;
    printf("%s\n", x >= 30 ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 3108
#include "stdio.h"
//長方形の中に円があるか判定
//2018/02/05
int main(void){
  int w,h,x,y,r;
  scanf("%d %d %d %d %d", &w, &h, &x, &y, &r);
  if(((x-r) >= 0) && ((y-r) >= 0) && ((x+r) <= w) && ((y+r) <= h)){
    puts("Yes");
  }else{
    puts("No");
  }
}



Measured memory_bytes: 2080
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(x, a) for(auto &x : a)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};

int H, W, a[510][510];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> H >> W;
    rep(i, 0, H) rep(j, 0, W) cin >> a[i][j];
    vv<pair<pii, pii>> ans;
    rep(i, 0, H) {
      rep(j, 0, W) {
        if (j != W -1 && a[i][j] % 2) {
          ans.pb({{i+1, j+1}, {i+1, j+2}});
          a[i][j+1]++;
        }
      }
    }
    rep(i, 0, H-1) {
      if (a[i][W-1] % 2) {
        ans.pb({{i+1, W}, {i+2, W}});
        a[i+1][W-1]++;
      }
    }
    cout << ans.size() << endl;
    fore(x, ans) {
      cout << x.first.first << " " << x.first.second << " " << x.second.first << " " << x.second.second << endl;
    }
    return 0;
}



Measured memory_bytes: 5232
import java.util.Scanner;

public class Main {

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

		int n = sc.nextInt();
		int l = sc.nextInt(); // 使用しない

		String[] s = new String[n];
		for (int i = 0; i < s.length; i++) {
			s[i] = sc.next();
		}
		sc.close();

		int imin;
		for (int i = 0; i < s.length - 1; i++) {
			imin = i;
			for (int j = i + 1; j < s.length; j++) {
				if (s[imin].compareTo(s[j]) > 0) {
					imin = j;
				}
			}
			if (imin != i) {
				exchange(s, imin, i);
			}
		}

		String sum = "";
		for (String str : s) {
			sum += str;
		}

		System.out.println(sum);
	}

	public static void exchange(String[] s, int a, int b) {
		String str = s[a];
		s[a] = s[b];
		s[b] = str;
	}

}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
//mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
string s1,s2;
int main() {
	cin>>s1>>s2;
	int i,j,cnt=0;
	rep(i,0,SZ(s1)){
		if(s1[i]!=s2[i]){
			printf("No"); 
			return 0;
		}
	}
	printf("Yes");

} 

Measured memory_bytes: 3692
a,b,c,k = list(map(int,input().split()))

unfair = 10**18

if k%2 ==0:
	if abs(a-b) <= unfair:
		print(a-b)
	else:
		print('Unfair')
else:
	if abs(b-a) <= unfair:
		print(b-a)
	else:
		print('Unfair')


Measured memory_bytes: 2940
#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	int h[n];
	for(int i=0;i<n;i++)cin>>h[i];
	h[0]--;
	for(int i=1;i<n;i++){
		if(h[i]>h[i-1])h[i]--;
		if(h[i]<h[i-1]){
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
}


Measured memory_bytes: 640
# encoding: utf-8                                                                                            

class Graph
  INF = 0x3fffffff
  def initialize(v)
    @v = v
    @edges = []
    @g = []
    @v.times.each { |idx| @g << Hash.new}
    @dists = [INF] * @v
    @prevs = [-1] * @v
  end

  def add_edge(u, v, w)
    @g[u][v] = w
  end

  def dijkstra(s)
    @dists[s] = 0
    que = { }
    que[s] = 0


    while not que.empty?
      v, d = que.min_by { |key, val| val}
      que.delete_if { |key, val| key == v and val == d}
      @g[v].each do |to, dist|
        if @dists[to] > @dists[v] + dist
          @prevs[to] = v
          @dists[to] = @dists[v] + dist
          que[to] = @dists[to]
        end
      end
    end
  end

  def solve(s)
    dijkstra(s)
    @dists.each_with_index do |dist, idx|
      puts "#{idx} #{dist}"
    end
  end

end


def input
  n = gets.to_i
  graph = Graph.new(n)
  (1..n).each do |node|
    arr = gets.rstrip.split(/\s/).map(&:to_i)
    u, k, edges = arr[0], arr[1], arr[2..-1]
    k.times { |ik| graph.add_edge(u, edges[2 * ik], edges[2 * ik + 1])}
  end
  graph
end

g = input
g.solve(0)

Measured memory_bytes: 6336
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector
;
#define vvec(s) vector<vector
> ;
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(),s.end()
void vout(vector<int> v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    lli n;
    cin>>n;
    vvi rec(n,vi(3,0));
    vi ans(n+1,0);
    ans[n]=0;
    rep(i,n-1){
        cin>>rec[i+1][0]>>rec[i+1][1]>>rec[i+1][2];
    }
    for(int i=1;i<=n-1;i++){
        for(int j=i;j<=n-1;j++) ans[j]=0;
        for(int j=i;j<=n-1;j++){
            if(j==i){
                ans[i]=rec[i][1]+rec[i][0];
            }
            else{
                if(ans[i]<=rec[j][1]){
                    ans[i]=rec[j][1]+rec[j][0];
                }
                else{
                    if(ans[i]%rec[j][2]==0){
                        ans[i]+=rec[j][0];
                    }
                    else{
                        ans[i]+=rec[j][2]-ans[i]%rec[j][2]+rec[j][0];
                    }
                }
            }
        }
        out(ans[i]);
    }
out(ans[n]);

}

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

#define ll long long
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define vi vector<int>
#define vl vector<long long>
#define sz size()
#define x first
#define y second
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;
int n;
vi g[100100];
int used[100100], a[100100], lvl[100100];

void dfs(int v, int l) {

	used[v] = 1;
	lvl[v] = l;
	for(int i = 0; i < g[v].sz; i++) {
		int to = g[v][i];
		if(!used[to]) {
			dfs(to, l + 1);
		}
	}
}

int main() {
	
	cin >> n;
	for(int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		a[i] = x;
		g[i].pb(x);
	}

	dfs(1, 1);
	
	if(lvl[2] == 0) {
		cout << -1;
	} else {
		cout << lvl[2] - 1;
	}


	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int H, W;
vector<string> fi;
int Left[2100][2100], Right[2100][2100], Up[2100][2100], Down[2100][2100];

int main() {
  // 入力
  cin >> H >> W;
  fi.resize(H);
  for (int i = 0; i < H; ++i) cin >> fi[i];

  // 前処理
  for (int i = 0; i < H; ++i) {
    int cur = 0;
    for (int j = 0; j < W; ++j) {
      if (fi[i][j] == '#')
        cur = 0;
      else
        ++cur;
      Right[i][j] = cur;
    }
  }
  for (int i = 0; i < H; ++i) {
    int cur = 0;
    for (int j = W - 1; j >= 0; --j) {
      if (fi[i][j] == '#')
        cur = 0;
      else
        ++cur;
      Left[i][j] = cur;
    }
  }
  for (int j = 0; j < W; ++j) {
    int cur = 0;
    for (int i = 0; i < H; ++i) {
      if (fi[i][j] == '#')
        cur = 0;
      else
        ++cur;
      Up[i][j] = cur;
    }
  }
  for (int j = 0; j < W; ++j) {
    int cur = 0;
    for (int i = H - 1; i >= 0; --i) {
      if (fi[i][j] == '#')
        cur = 0;
      else
        ++cur;
      Down[i][j] = cur;
    }
  }

  // 集計
  int res = 0;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (fi[i][j] == '#') continue;
      res = max(res, Left[i][j] + Right[i][j] + Up[i][j] + Down[i][j] - 3);
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 72448
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

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

#define REP(i, n) for(ll i = 0; i < n; i++)










int main(){
    ll h, w;
    cin >> h >> w;
    vector<vector<ll>> a(h, vector<ll>(w));
    vector<vector<ll>> b(h, vector<ll>(w));
    REP(i, h){
        REP(j, w){
            cin >> a[i][j];
        }
    }
    REP(i, h){
        REP(j, w){
            cin >> b[i][j];
        }
    }
    using boolean = int;
    vector<vector<vector<boolean>>> dp(h, vector<vector<boolean>>(w, vector<boolean>(80 * (h + w))));
    dp[0][0][abs(a[0][0] - b[0][0])] = true;
    REP(i, h){
        REP(j, w){
            REP(k, 80 * (h + w)){
                if(i < h - 1){
                    ll d = abs(a[i + 1][j] - b[i + 1][j]);
                    dp[i + 1][j][abs(k + d)] |= dp[i][j][k];
                    dp[i + 1][j][abs(k - d)] |= dp[i][j][k];
                }
                if(j < w - 1){
                    ll d = abs(a[i][j + 1] - b[i][j + 1]);
                    dp[i][j + 1][abs(k + d)] |= dp[i][j][k];
                    dp[i][j + 1][abs(k - d)] |= dp[i][j][k];
                }
            }
        }
    }
    /*
    REP(k, 5 * (h + w)){
        REP(i, h){
            REP(j, w){
                cerr << dp[i][j][k] << " ";
            }
            cerr << endl;
        }
        cerr << endl;
    }
    */
    REP(k, 80 * (h + w)){
        if(dp[h - 1][w - 1][k]){
            cout << k << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 324608
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  int n, k;
  scanf("%d %d", &n, &k);
  vector<int> v;
  SV(n,v);

  sort(ALL(v), greater<int>());
  llong ans = 0;
  REP(i,k){
    ans += v[i];
  }

  printf("%lld\n", ans);
  return 0;
}



Measured memory_bytes: 256
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 3
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int, n)
	xa := make([]int, n)
	bb := make([]int, n)
	xb := make([]int, n)

	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	for i := 0; i < n; i++ {
		xa[i] = aa[i] ^ aa[(i+1)%n]
	}
	for i := 0; i < n; i++ {
		bb[i] = getNextInt(scanner)
	}
	for i := 0; i < n; i++ {
		xb[i] = bb[i] ^ bb[(i+1)%n]
	}

	table := make([]int, n+1)
	table[0] = -1
	j := -1
	for i := 0; i < n; i++ {
		for j >= 0 && xb[i] != xb[j] {
			j = table[j]
		}
		j++
		table[i+1] = j
	}

	j = 0
	for i := 0; i < n*2; i++ {
		if j == n {
			fmt.Fprintln(writer, fmt.Sprintf("%d %d", i%n, aa[i%n]^bb[0]))
			j = table[j]
		}
		for j >= 0 && xa[i%n] != xb[j] {
			j = table[j]
		}
		j++
	}
}


Measured memory_bytes: 19968
import sys
import math
import bisect

def solve(s):
    for i in range(26):
        c = chr(i + ord('a'))
        if c not in s:
            return c
    return None

def main():
    ans = solve(input())
    if ans:
        print(ans)
    else:
        print('None')

if __name__ == "__main__":
    main()


Measured memory_bytes: 39024
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename TYPE>
void print_vec(const vector<TYPE>& v, int num=0){
  if(num == 0) num = (int)v.size();
	for(int i=0; i<num; i++){
		cout << v[i]; if(i!=num-1) cout << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

ll gcd(ll x, ll y){
  if(y==0) return x;
  return gcd(y, x%y);
}

int main(){
  ll x, y;
  cin >> x >> y;
  ll ans = gcd(x, y);

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




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

int main(){
  int d,g;
  cin >> d >> g;
  vector<int> p(d),c(d);
  for(int i=0;i<d;i++){
    cin >> p.at(i) >> c.at(i);
  }
  vector<int> dp(1001);
  for(int i=0;i<d;i++){
    for(int k=1000;k>=1;k--){
      for(int j=1;j<=p.at(i)&&j<=k;j++){
        dp.at(k)=max(dp.at(k),
          dp.at(k-j)+(i+1)*100*j+(j==p.at(i)?c.at(i):0));
      }
    }
  }
  for(int i=0;i<=1000;i++){
    if(dp.at(i)>=g){
      cout << i << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
n=int(input())
s=list(input())

r=[i for i, _x in enumerate(s) if _x == 'R']
g=[i for i, _x in enumerate(s) if _x == 'G']
b=[i for i, _x in enumerate(s) if _x == 'B']

ans=len(r)*len(g)*len(b)

for i in range(n-2):
  for j in range(i+1,n-1):
    k=2*j-i
    if k<n:
      if s[i]!=s[j] and s[j]!=s[k] and s[i]!=s[k]:
        ans-=1
        
print(ans)

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

int main() {
    ll k;
    cin >> k;
    ll now=0;
    ll count=0;
    while(count<k){
        count++;
        now=(now*10+7)%k;
        if(now==0){
            cout << count << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}


Measured memory_bytes: 3564
def dt(a):
    for x in range(1,9):
        if 4**x > a:
            y = x-1
            break
    n = ''
    for i in range(y+1):
        t = a // 4 ** (y-i)
        n += str(t)
        a -= t * 4 ** (y-i)
    return n

def MP(a,b):
    return (len(a)-1)*10 + abs(sum(a)-b)

N,A,B,C = map(int, input().split())
H = [int(input()) for i in range(N)]
ls = [[],[],[]]
ans = 10**18

for i in range(4**N):
    jj = dt(i)
    j = jj.zfill(N)
    for (k,x) in enumerate(j):
        if x == '0':
            continue
        elif x == '1':
            ls[0].append(H[k])
        elif x == '2':
            ls[1].append(H[k])
        elif x == '3':
            ls[2].append(H[k])
    else:
        if ls[0] and ls[1] and ls[2]:
            ans = min(ans, MP(ls[0],A)+MP(ls[1],B)+MP(ls[2],C))
        ls = [[],[],[]]

print(ans)

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

void print(int a, int b, string str)
{
  cout << str.substr(a, b-a+1) << endl;
}

string replace(int a, int b, string str, string p)
{
  str.replace(a, b-a+1, p);
  return str;
}

string reverse(int a, int b, string str)
{
  int n;
  n = b - a + 1;
  string tmp;
  tmp = str.substr(a, n);
  for (int i=0; i<n; i++) str[a+i] = tmp[n-i-1];
  return str;
}

int main()
{
  string str;
  int n;
  cin >> str >> n;
  for (int i=0; i<n; i++) {
    string order;
    int a, b;
    cin >> order >> a >> b;
    if (order=="print") print(a, b, str);
    if (order=="reverse") str = reverse(a, b, str);
    if (order=="replace") {
      string p;
      cin >> p;
      str = replace(a, b, str, p);
    }
  }
  return 0;
}



Measured memory_bytes: 3200
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
 
a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])
 
ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

Measured memory_bytes: 47336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int N, Q;
int p[100010];
string T[100010];
int NUM[100010];

vector<int> G[100010];
int ans[100010];
bool used[100010];

void dfs(int u, int k) {
	if(used[u] || ans[u] == k) return;
	ans[u] = k;
	for(auto v : G[u]){
		dfs(v, k);
	}
}

int main(void) {
	while(1){
		scanf("%d %d", &N, &Q);
		if(N == 0 && Q == 0) break;
		rep(i, N - 1) scanf("%d", &p[i]);
		rep(i, Q){
			cin >> T[i] >> NUM[i];
		}
		rep(i, Q) NUM[i]--;

		rep(i, 100010) G[i].clear();
		rep(i, 100010) ans[i] = 0;
		rep(i, 100010) used[i] = false;

		rep(i, N - 1) G[p[i] - 1].pb(i + 1);

		ll ret = 0;
		rep(i, Q) {
			if(T[i] == "Q") {
				// printf("ans %d\n", ans[NUM[i]] + 1);
				ret += ans[NUM[i]] + 1;
			}else{
				dfs(NUM[i], NUM[i]);
				used[NUM[i]] = true;
			}
		}
		printf("%lld\n", ret);
	}
	return 0;
}

Measured memory_bytes: 18264
#include<stdio.h>
    #include<math.h>
    int asif(int x, int y) {
        int pow = 10;
        while(y >= pow)
            pow *= 10;
        return x * pow + y;
    }
    int main()
    {
        int a,b,c,d;
        scanf("%d %d",&a,&b);
            c=asif(a,b);
            d=sqrt(c);
            if((d*d)==c)
                printf("Yes\n");
            else
                printf("No\n");
        return 0;
    }

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

const int bm = 200001;
ll BIT[bm];
void add(int A, ll B) {
	while (A <= bm) {
		BIT[A] = max(BIT[A], B);
		A += A & -A;
	}
}
ll query(int A) {
	ll kotae = 0;
	while (A > 0) {
		kotae = max(BIT[A], kotae);
		A -= A & -A;
	}
	return kotae;
}

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


	int N;
	cin >> N;
	int h[200000];
	rep(i, N) cin >> h[i];

	rep(i, N) {
		int a;
		cin >> a;

		add(h[i], query(h[i]) + a);

	}

	co(query(N));


	Would you please return 0;
}

Measured memory_bytes: 2560
n, k, c = map(int,input().split())
s = input()

l = []
r = []
i=0
while len(l)<k:
    if s[i]=="o":
        l.append(i)
        i += c+1
    else:
        i +=1

i=0
while len(r)<k:
    if s[n-1-i] == "o":
        r.append(n-1-i)
        i += c+1
    else:
        i += 1

for i in range(k):
    if l[i] == r[-i-1]:
        print(l[i]+1)

Measured memory_bytes: 20612
# include <iostream>
# include <cstdio>
using namespace std;
int main()
{
    int x, y, k;
    scanf("%d%d%d",&x,&y,&k);
    for(int i=0; i<=x; ++i)
        for(int j=0; j<=y; ++j)
        if(i*y+j*x-i*j*2 == k) return 0*puts("Yes");
    puts("No");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int, int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define sws ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
#define teto(a, b) ((a+b-1)/(b))
using namespace std;

const int MAX = 200010;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LLINF = 1000000000000000000;
const ld EPS = 1e-7;

// Extra
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define forne(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
//

int n;
vl v;
ll tab[3001][3001][2];

ll dp(int move, int st, int player) {
    if(move >= n) {
        return 0;
    }
    if(tab[move][st][player] != -1)
        return tab[move][st][player];
    int end = n-1 - (move-st);

    ll res = 0;
    if(player == 0) {
        ll val1 = v[st] + dp(move+1, st+1, !player);
        ll val2 = v[end] + dp(move+1, st, !player);
        res = max(val1, val2);
    }
    else {
        ll val1 = -v[st] + dp(move+1, st+1, !player);
        ll val2 = -v[end] + dp(move+1, st, !player);
        res = min(val1, val2);
    }

    return tab[move][st][player] = res;
}

int main() {
    memset(tab, -1, sizeof(tab));
    cin >> n;

    v.assign(n, 0);
    forn(i, n) {
        cin >> v[i];
    }

    cout << dp(0, 0, 0) << endl;

    return 0;
}


Measured memory_bytes: 144588
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

template<class T, class S> inline bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S> inline bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}





int main(){
    long long A, B, C;
    scanf("%lld %lld.%lld", &A, &B, &C);
   // std::cout << A << " " << B << " " << C << std::endl;
    std::cout << (A * (100*B + C)) / 100 << std::endl;
    return 0;
}


Measured memory_bytes: 3676
import java.util.Scanner

object Main{
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)

    val N = sc.nextLong()
    var num = 0 :Double

    var n = N

    for (i <- 9 to 0 by -1) {
      val tmp = Math.pow(10, i).toLong
      if (n / tmp >= 1) {
        num += n / tmp
      }
      n = n % tmp
    }
    
    if (0 == N % num) println("Yes")
    else println("No")
  }
}

Measured memory_bytes: 27340
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
int read()
{  int f=1,x=0;
   char ch=getchar();
   for(;ch>'9'||ch<'0';ch=getchar())if(ch=='-') f=-1;
   for(;ch<='9'&&ch>='0';ch=getchar())x = x * 10 + ch - '0';
   return x*f;
}
int n, k, a[200005],ans;
int main()
{    for(int i=1;i<=5;i++){cin>>a[i];if(a[i]==0)ans=i;}
     cout<<ans;

       

      return 0;
}

Measured memory_bytes: 3620
program CADDi2018_B

  ! <module>s to import
  use, intrinsic :: iso_fortran_env

  ! require all variables to be explicitly declared
  implicit none

  ! variables for this <program>
  integer(kind=INT32) :: num_plates_usable, num_plates_given
  integer(kind=INT32) :: val_width_wanted,  val_height_wanted
  integer(kind=INT32) :: val_width_given,   val_height_given

  ! support variables for this <program>
  integer :: itr

  ! STEP.01
  ! read out the number of usable plates & wanted width and height of plates
  read(unit=INPUT_UNIT, fmt=*) num_plates_given, val_height_wanted, val_width_wanted

  ! STEP.02
  ! initialize the counter
  num_plates_usable = 0

  ! STEP.03
  do itr = 1, num_plates_given, 1
    
    ! STEP.03.01
    ! read out the given width and height of plates
    read(unit=INPUT_UNIT, fmt=*) val_height_given, val_width_given

    ! STEP.03.02
    ! judge whether the given plate is a usable one
    if (val_height_given .ge. val_height_wanted .and. val_width_given .ge. val_width_wanted) then
      num_plates_usable = num_plates_usable + 1
    end if

  end do

  ! STEP.04
  ! output the number of usable plates
  write(unit=OUTPUT_UNIT, fmt='(I0)', advance='yes') num_plates_usable

end program CADDi2018_B

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

typedef vector<vector<int> > graph;

#define REP(i,n) for(int i=0; i<n; i++)


void visit(graph& g, vector<int>& PostOrder, vector<bool>& visited, int ps)
{
	visited[ps]=1;
	int S=g[ps].size();
	REP(i,S)
	{
		int next=g[ps][i];
		if(visited[next]) continue;
		visit(g, PostOrder, visited, next);
	}
	
	PostOrder.push_back(ps);
}

void walk(graph& g, vector<int>& in, int ps, int gcnt)
{
	in[ps]=gcnt;
	
	int S=g[ps].size();
	REP(i,S)
	{
		int next=g[ps][i];
		if(in[next]!=-1) continue;
		walk(g,in,next,gcnt);
	}
}

//StronglyConnectedComponent
int SCC(vector<int>& in, int V, graph& g, graph& rg)
{
	int gcnt=0;
	vector<int> PostOrder;
	vector<bool> visited(V,false);
	
	REP(i,V)
	{
		if(visited[i]) continue;
		visit(g,PostOrder,visited, i);
	}
		
	for(int i=PostOrder.size()-1; i>=0; --i)
	{
		if(in[PostOrder[i]]==-1) 
		{
			walk(rg,in,PostOrder[i],gcnt++);
		}
	}

	return gcnt;
}

int recipe[1050], self[1050],reduce[1050];

int dfs(int p, vector<bool>& use, graph& g, graph& c)
{
	use[p]=1;

	int ret=0;
	for(int i=0; i<g[p].size(); i++)
	{
		int next=g[p][i];
		if(use[next]) continue;
		ret+=dfs(next, use, g, c);
		ret+=c[p][i];
	}

	return ret;

}

int calc(vector<int>& v, vector<bool>& created, graph& g, graph& c)
{
	vector<bool> use(10000, 1);
	for(int i=0; i<v.size(); i++)
		use[v[i]]=0;

	int ret=(1<<24);
	for(int i=0; i<v.size(); i++)
	{
		vector<bool> u(use);
		int p=v[i], t=dfs(p,u,g,c);
		if(created[recipe[p]])  t+=reduce[p];
		else					t+=self[p];
		
		ret=min(ret, t);
	}

	for(int i=0; i<v.size(); i++)
		created[v[i]]=1;

	return ret;
}

int main()
{
	int N;
	while(cin >> N, N)
	{
		graph g(N), rg(N), c(N), rc(N);

		int dcnt=0;
		map<string, int> dic;
		for(int i=0; i<N; i++)
		{
			string s,t;
			int a,b,u,v;
			cin >> s >> a >> t >> b;

			if(!dic.count(s)) dic[s]=dcnt++;
			if(!dic.count(t)) dic[t]=dcnt++;
			
			u=dic[s];
			v=dic[t];

			 g[u].push_back(v);
			rg[v].push_back(u);
			 c[u].push_back(b);
			rc[v].push_back(b);

			self[u]=a;
			recipe[u]=v;
			reduce[u]=b;
		}

		vector<int> in(N, -1);
		int gcnt=SCC(in,N,rg,g);

		vector<vector<int> > loop(gcnt);
		for(int i=0; i<N; i++)
			loop[in[i]].push_back(i);

		vector<bool> created(N, 0);

		int ans=0;
		for(int i=0; i<gcnt; i++)
		{
			ans+=calc(loop[i], created, rg, rc);
		}

		printf("%d\n", ans);
	}
}

/*
4
gu 20 pa 10
ci 20 gu 10
pa 20 ci 10
hoge 20 pa 10
*/

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

int main(){
    int a,b,k;
    cin >> a >> b >> k;
    int c=min(a,b);
    int d=max(a,b);
    int ans;
    int cnt=0;
    for(int i=c;i>0;i--){
        if(cnt==k) break;
        if(d%i==0&&c%i==0){
            ans=i;
            cnt++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 
                                                           
*/
/* }}} */

#include <bits/stdc++.h>
using namespace std;

// #define int long long

/* cpp template {{{ */

/* short */
#define pb push_back
#define mp make_pair
#define print(x) cout << x << '\n'
#define Fi first
#define Se second

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define DEPS(i, a, n) for (int i = (a); i >= n; i--)
#define DEP(i, n) for (int i = (n); i >= 0; i--)

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

/* const */
const int INF = 999999999;
const double EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool is_uruu(int y) {return y % 4 == 0 && y % 100 != 0 || y % 400 == 0;}
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}

/* }}} */

const int MAX = 1e6;
bool prime[MAX + 1];

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

  fill(prime, prime + MAX + 1, true);
  prime[0] = prime[1] = false;

  for (int i = 2; i <= MAX; i++){
    if (prime[i]){
      for (int j = i + i; j <= MAX; j += i){
        if (prime[j]) prime[j] = false;
      }
    }
  }

  int a, d, n;
  while (cin >> a >> d >> n, a || d || n){
    for (int i = a, j = 0; j < n; i += d){
      if (prime[i]){
        j++;
        if (j == n){
          print(i);
        }
      }
    }
  }

  return 0;
}

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

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

	return 0;
}


Measured memory_bytes: 256
import math

N, D = list(map(int, input().split()))

zahyo = [[int(i) for i in input().split()] for N in range(N)]

A = 0

for i in range(N):
        
        d = math.sqrt((zahyo[i][0]) **2 + (zahyo[i][1]) ** 2)
        
        if d <= D:
            A += 1
        
print(A)

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int INF = 1000000000;
const int MOD = 1000000007;
const double eps = 1e-9;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int a, b, h;
    cin >> a >> b >> h;
    cout << (a + b) * h / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e10;
const ll MAX_N = 1010;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];

void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	if (n > k * 2) {

	}
	return fac[n] / (fac[k] * fac[n - k]);
}

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

//long longしか使わない
//素数は1より大きい
int main() {
	ll n, p;
	cin >> n >> p;
	vector<ll>a(n);
	bool flag = false;
	rep(i, n) {
		cin >> a[i];
		if (a[i] % 2)flag = true;
	}
	ll ans = 1;
	if (flag) {
		rep(i, n - 1) {
			ans *= 2;
		}
	}
	else {
		if (p == 1) {
			cout << 0 << endl;
			return 0;
		}
		rep(i, n) {
			ans *= 2;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3576
import copy
n = int(input())
p = list(map(int,input().split()))
q = list(map(int,input().split()))

a = list()
for i in range(1,n+1):
    a.append(int(i))
b = copy.copy(a)

kai = 1
for i in range(1,n+1):
    kai = kai * i

pans = 0
qans = 0
for i in range(n):
    kai = kai / (n-i)
    pans +=  kai * ( a.index(p[i]) + 1 )
    a.remove(p[i])
    
    qans +=  kai * ( b.index(q[i]) + 1 )
    b.remove(q[i])

print(int(abs(pans - qans)))

Measured memory_bytes: 3444