akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<double, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

int n;

double dijkstra(int s, vector<vector<pair<int, double>>> &G){
    vector<double> dist(1010, INF);
    priority_queue<P, vector<P>, greater<P>> que;
    dist[s] = 0;
    que.emplace(0, s);

    while(que.size()){
        double ccost; int cv;
        tie(ccost, cv) = que.top();
        que.pop();

        if(dist[cv] < ccost) continue;

        for(auto nxt : G[cv]){
            int nv; double ncost;
            tie(nv, ncost) = nxt;
            
            if(dist[cv] + ncost < dist[nv]){
                dist[nv] = dist[cv] + ncost;
                que.emplace(dist[nv], nv);
            }
        }
    }

    return dist[n+1];
}

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

    double xs, ys, xt, yt; cin>>xs>>ys>>xt>>yt;
    cin>>n;
    vector<double> x(n), y(n), r(n);
    for(int i=0; i<n; i++) cin>>x[i]>>y[i]>>r[i];

    vector<vector<pair<int, double>>> G(n+2);
    for(int i=0; i<n; i++){
        double dist = sqrt(abs(x[i] - xs) * abs(x[i] - xs) + abs(y[i] - ys) * abs(y[i] - ys));
        dist = max(dist - r[i], 0.0);
        G[n].emplace_back(i, dist);
        G[i].emplace_back(n, dist);
    }
    G[n].emplace_back(n+1, sqrt(abs(xt - xs) * abs(xt - xs) + abs(yt - ys) * abs(yt - ys)));

    for(int i=0; i<n; i++){
        double dist = sqrt(abs(x[i] - xt) * abs(x[i] - xt) + abs(y[i] - yt) * abs(y[i] - yt));
        dist = max(dist - r[i], 0.0);
        G[n+1].emplace_back(i, dist);
        G[i].emplace_back(n+1, dist);
    }
    G[n+1].emplace_back(n, sqrt(abs(xt - xs) * abs(xt - xs) + abs(yt - ys) * abs(yt - ys)));
    
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(i == j) continue;

            double dist = sqrt(abs(x[i] - x[j]) * abs(x[i] - x[j]) + abs(y[i] - y[j]) * abs(y[i] - y[j]));
            dist = max(dist - r[i] - r[j], 0.0);
            G[i].emplace_back(j, dist);
        }
    }

    double ans = dijkstra(n, G);

    printf("%.10f\n", ans);
}

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

typedef long long ll;

ll gcds(ll a,ll b){
    if(a<b){
        swap(a,b);
    }
    ll r=a%b;
    if(r==0){
        return b;
    }
    while(r>0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}


ll lcms(ll a,ll b){
    ll mmr=gcds(a,b);
    a=a/mmr;
    b=b/mmr;
    return a*b*mmr;
}

/*
int main(){
    cout<<gcds(12,16)<<" "<<lcms(12,16)<<endl;
}
*/


int main(){
    ll N;
    cin>>N;
    vector<ll> T(N);
    for(ll i=0;i<N;i++){
        cin>>T.at(i);
    }
    sort(T.begin(),T.end());
    reverse(T.begin(),T.end());

    ll var=T.at(0);
    for(ll i=1;i<N;i++){
        var=lcms(var,T.at(i));
    }

    cout<<var<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#define M 100

int main(void){
  int i, j, A[M], N, v;

  scanf("%d", &N);
  for(i=0; i<N; i++){
    scanf("%d", &A[i]);
  }

  for(i=0; i<N-1; i++)
    printf("%d ", A[i]);
  printf("%d\n", A[N-1]);
  
  for(i=1; i<N; i++){
    v = A[i];
    j = i-1;
    
    while(j>=0 && A[j] > v){
      A[j+1] = A[j];
      j--;
      A[j+1] = v;
    }

  for(j=0; j<N-1; j++)
    printf("%d ", A[j]);
  printf("%d\n", A[N-1]);
  }
  
  return 0;
}



Measured memory_bytes: 2084
#include"bits/stdc++.h"
using namespace std;


int main() {
	long long a, b, x;
	cin >> a >> b >> x;

	long long cnt = 0;
	long long y, z;
	if (a%x == 0) y = a / x - 1;
	else y = a / x;
	cnt = b / x - y;
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  double w,h;
  int x,y,c;
  cin >> w >> h >> x >> y;
  double area = (w*h)/2.00000;
  if (x==w/2 & y==h/2) {
    c=1;
  }
  else {
    c=0;
  }
  cout << area <<" "<< c << endl;
}


Measured memory_bytes: 256
/// Code By t_bone_289 (Tushar Singh)
/// An Immature Programmer.... I'm still developing !!
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 1000000007
#define error(x) cout << #x << " = " << x << endl;
#define pi 3.14159265358979323846
typedef long long ll;
typedef long double ld;
template <typename T>
void ContainerError(T &v){cout<<"{";for(auto &x:v){cout<<x<<',';}cout<<"}"<<endl;return;}
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
ll powmod(ll base,ll exp,ll MOD){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
ll mpow(ll base,ll exp){ll res=1;while(exp>0){if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return (res);}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    map<string,ll> m;
    for(ll i=0;i<n;i++)
    {
    	string s;
    	cin>>s;
    	m[s]++;
    }
    map<ll,std::vector<string> > mp;
    for(auto x:m)
    {
    	ll k = x.se;
    	mp[k].pb(x.fi);
    }
    auto it = mp.rbegin();
    std::vector<string> vv = (*it).se;
    for(auto x:vv)
    {
    	cout<<x<<endl;
    }
    return 0;
}


Measured memory_bytes: 27120
import collections

n, a = [int(x) for x in input().split()]
X = [int(x) - a for x in input().split()]
ans = 0
sums = collections.Counter([0, X[0]])
for x in X[1:]:
    sums2 = collections.Counter()
    for s, c in sums.items():
        sums2[s + x] += c
    sums += sums2

print(sums[0] - 1)


Measured memory_bytes: 3700
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <complex>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

const ll MOD = 1000000007;
int main(){
    int k,x; cin >> k >> x;
    if(k*500>=x) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
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 c = sc.nextInt();
		int k = sc.nextInt();
		
		new Main().execute(a, b, c, k);
	}

	public void execute(int a, int b, int c, int k) {
		List<int[]> cardPoint = new ArrayList<>();
		int[] firstCard = {a, b, c};
		cardPoint.add(firstCard);
		for (int i = 0; i < k; i++) {
			List<int[]> nextCardPoint = new ArrayList<>();
			
			for (int[] cards : cardPoint) {
				int[] redCard = {cards[0] * 2, cards[1], cards[2]};
				int[] greenCard = {cards[0], cards[1] * 2, cards[2]};
				int[] blueCard = {cards[0], cards[1], cards[2] * 2};
				
				if (judge(redCard) || judge(greenCard) || judge(blueCard)) {
					System.out.println("Yes");
					return;
				}
				nextCardPoint.add(redCard);
				nextCardPoint.add(greenCard);
				nextCardPoint.add(blueCard);
			}
			cardPoint = nextCardPoint;
		}
		System.out.println("No");
	}
	
	private boolean judge(int[] card) {
		return card[0] < card[1] && card[1] < card[2];
	}
}




Measured memory_bytes: 27052
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;


int main() {

    ll N, K;
    vector<ll> tree;

    cin >> N >> K;
    tree.resize(N, 0);

    for (ll i = 0; i < N; ++i)
        cin >> tree[i];

    sort(tree.begin(), tree.end());

    ll min = 10000000000;
    for(ll i=0; i+K-1<N; i+=1)
    {
        if(min>abs(tree[i]-tree[i+K-1]))
            min=abs(tree[i]-tree[i+K-1]);
    }

    cout<<min<<endl;

    return 0;
}


Measured memory_bytes: 1024
import bisect
N=int(input())
L=list(map(int,input().split()))
L.sort()
ans=0
for n in range(1,N):
  b=L[n]
  for k in range(n):
    a=L[k]
    index=bisect.bisect_left(L,a+b)
    ans+=(index-n-1)
print(ans)

Measured memory_bytes: 42332
def main():
    N, M, Q = (int(i) for i in input().split())
    T = [[int(i) for i in input().split()] for j in range(Q)]

    def dfs(A):
        if len(A) == N:
            ret = 0
            for (a, b, c, d) in T:
                if A[b-1] - A[a-1] == c:
                    ret += d
            return ret
        ret = 0
        s = A[-1] if A else 1
        for a in range(s, M+1):
            ret = max(ret, dfs(A + [a]))
        return ret

    print(dfs([]))


if __name__ == '__main__':
    main()


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

using namespace std;

#define intt long long

const int N = 100005;


int n, k;

int h[N];

intt dp[N];

int main() {

	cin >> n >> k;

	for (int i = 1; i <= n; i ++) {
		cin >> h[i];
	}

	dp[1] = 0;
	dp[2] = abs(h[2] - h[1]);

	for (int i = 3; i <= n; i ++) {
		dp[i] = LONG_LONG_MAX;
		for (int j = 1; j <= k; j ++) {
			if (i - j >= 1) {
				dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
			}
		}
	}

	cout << dp[n] << '\n';
	return 0;
}

Measured memory_bytes: 1536
import java.io.*;
class Main{
	public static void main(String[]args)throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb=new StringBuilder();
		String str=br.readLine();
		int i=0;
		do{
			i++;
			sb.append("Case ").append(i).append(": ").append(str).append("\n");
			str=br.readLine();
		}while(!str.equals("0"));
		System.out.print(sb.toString());
	}
}

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

#define ll long long
#define ii pair<int, int>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pi 3.14159265
#define oo 1000000000

using namespace std;
#define prime 1000000007

#define W(x) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << "\n";
using namespace std;

int n, m, b, c;
int a[100100];
ii v[100100];

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

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

	sort(a, a+n);

	for (int i = 0; i < m; ++i){
		scanf("%d %d", &b, &c);
		v[i] = {c, b};
	}

	sort(v, v+m);
	reverse(v, v+m);

	int r = 0, j = 0;
	while(j < n){
		while(j < n && r < n && v[r].ss && v[r].ff > a[j]){
			a[j] = v[r].ff;
			j++;
			v[r].ss--;
		}
		if(!v[r].ss) r++;
		else j++;
		if(r >= n) break;
	}

	ll ans = 0;
	for (int i = 0; i < n; ++i){
		ans += a[i];
	}

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

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'
#define all(x) x.begin(), x.end()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

using vvll = vector< vector<ll> >;
using vll = vector<ll> ;

const ll maxs = 2e5+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;


void pre(){



}

void solve(){
    
    ll x,y;
    cin >> x >> y;
    bool ans=false;
    for(ll i=0;i<=x;i++){
        ll F = 2*i;
        ll rem = x-i;
        if(F + (rem*4) == y){
            ans = true;
        }
    }
    if(ans)
        cout << "Yes";
    else
        cout << "No";

}

int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

Measured memory_bytes: 3648
# 2019-11-24 12:12:53(JST)
import sys

def main():
    n, m = map(int, sys.stdin.readline().split())
    xy = map(int, sys.stdin.read().split())
    xy = zip(xy, xy)

    count = dict((i, 1) for i in range(1, n+1))
    may_contain_red = set([1])

    for x, y in xy:
        count[x] -= 1; count[y] += 1
        if x in may_contain_red:
            may_contain_red.add(y)
            if count[x] == 0:
                may_contain_red ^= set([x])
    
    ans = len(may_contain_red)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 34940
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)


using namespace std;

typedef long long ll;

int main(){
    int N;
    int num;
    vector<int> vec,vec_p,vec_q;
    vector<vector<int> > vvec;

    scanf("%d",&N);

    rep(i,N){
        scanf("%d",&num);
        vec_p.push_back(num);
    }
    rep(i,N){
        scanf("%d",&num);
        vec_q.push_back(num);
    }

    rep(i,N)vec.push_back(i+1);


    do{
        vvec.push_back(vec);
    }while(next_permutation(vec.begin(),vec.end()));

    int int_p=0,int_q=0;

    for(int i=0;i!=vvec.size();++i){
        ++int_p;
        if(vvec[i]==vec_p){
            break;
        }
    }
   

    for(int i=0;i!=vvec.size();++i){
        ++int_q;
        if(vvec[i]==vec_q){    
            break;
        }
    } 
    
   
    cout<<abs(int_q-int_p)<<endl;      
}

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

using namespace std;

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

int solve(int n) {
  int res = 1;
  for (int i = 2; i * i <= n; i++) {
    if (n % i) continue;
    res *= i;
    while (n % i == 0) n /= i;
  }
  if (n != 1) res *= n;
  return res;
}

int main(void) {
  int p, q;
  cin >> p >> q;
  
  cout << solve(q / gcd(p, q)) << endl;

  return 0;
}


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

#define sz(x) (int)x.size()
#define ld long double
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second

using namespace std;

ll n;
map<ll, ll> m;
void f()  {  
    while (n % 2 == 0)  {  
        m[2]++;
        n = n/2;  
    }  
    for (ll i = 3; i <= sqrt(n); i = i + 2)  {  
        while (n % i == 0)  {  
            m[i]++;
            n = n/i;  
        }  
    }  
    if (n > 2)  
        m[n]++;
}  
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    f();
    ll res = 0;
    for(auto i : m){
        // cout << i.s << " " << i.f << "\n";
        ll cur = 0, cnt = 0;
        while(i.s >= cur){
            cnt++;
            cur += cnt;
        }
        // cout << cnt << "\n";
        res += cnt - 1;
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 3672
import java.util.*;

class Main {

    public static void main(String[] args) {

      //入力値取得
      Scanner in = new Scanner(System.in);
      String weather = in.next();
      
      //入力値によって出力する天気を変更する
      switch(weather){
        case"Sunny":
          System.out.println("Cloudy");
          break;
       	case"Cloudy":
          System.out.println("Rainy");
          break;
        case"Rainy":
          System.out.println("Sunny");
          break;
        default:
          System.out.println("Sunny");
        }
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
typedef complex<ld> com;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

void update(ll &mi, ll &ma, ll val, ll val2) {
	if (val > val2) swap(val, val2);
	chmax(mi, val); chmin(ma, val2);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	for (int i = 1; i < n; i++) a[i] += a[i - 1];
	ll ans = INF;
	for (int i = 1; i < n - 2; i++) {
		ll mi = -INF; ll ma = INF;
		ll leftsum = a[i];
		ll leftidx = lower_bound(all(a), leftsum / 2) - a.begin();
		if (leftidx != i) update(mi, ma, a[leftidx], a[i] - a[leftidx]);
		leftidx--;
		if (leftidx != -1) update(mi, ma, a[leftidx], a[i] - a[leftidx]);
		ll mi2 = -INF; ll ma2 = INF;
		ll rightsum = a[n - 1] - a[i];
		ll rightidx = lower_bound(all(a), leftsum + rightsum / 2) - a.begin();
		if (rightidx != n - 1) update(mi2, ma2, a[rightidx] - a[i], a[n - 1] - a[rightidx]);
		rightidx--;
		if (rightidx != i) update(mi2, ma2, a[rightidx] - a[i], a[n - 1] - a[rightidx]);
		chmin(ans, max(ma, ma2) - min(mi, mi2));
	}
	cout << ans << '\n';
}

Measured memory_bytes: 1792
def show2dlist(nlist,r,c):
    for x in xrange(0,r):
        nlist[x] = map(str,nlist[x])
        ans = " ".join(nlist[x])
        print ans
def showlist(nlist,nlistlen):
    for x in xrange(nlistlen):
        print nlist[x],

r,c = map(int,raw_input().split())
table = [[0 for x in xrange(c)] for y in xrange(r)]
i = 0
for x in xrange(r):
    table[i] = map(int,raw_input().split())
    i+=1
# calc table
csumlist =[0 for x in xrange(0,c+1)]
for x in xrange(0,r):
    table[x].append(sum(table[x]))
    for y in xrange(0,c+1):
        csumlist[y] += table[x][y]
show2dlist(table,r,c+1)
showlist(csumlist,c+1)

Measured memory_bytes: 6608
n = int(input())
l = list(map(int, input().split()))
a = []
b = 0
for m in range(n):
    a.append(0)
for m in range(n):
    a[l[m]-1] += 1
for m in range(n):
    b += int(a[m]*(a[m]-1)/2)
for m in range(n):
    print(b-a[l[m]-1]+1)

Measured memory_bytes: 25716
#include <stdio.h>
#include <iostream>
#include <vector>
#include <assert.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef long long ll;
int main()
{
	int n;
	scanf("%d", &n);
	vector<int> v(n);
	int last = -1e9;
	int res = 0;
	int c = 0;
	for (auto &x : v) {
		scanf("%d", &x);
		if (x == last)
			++c;
		else {
			res += c / 2;
			last = x;
			c = 1;
		}
	}
	res += c / 2;
	cout << res << endl;
	return 0;
}

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

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 T> inline T gcd(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T lcm(T a,T b){return a*b/gcd(a,b);}

const int INF=1e9;
const double eps=0.0000000001;

int main(){
  int n,k;
  cin >> n >> k;
  cout << n-k+1 << endl;
}


Measured memory_bytes: 256
#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() {
    ll n;
    cin >> n;
    ll m = (ll)floor(sqrt(n));
    
    ll res = 1;
    if(n != 2) ++res;
    
    for(ll i = 2; i <= m; ++i){
        if(n%i == 1){
            //cout << i << endl;
            if(i * i != n-1){
                res += 2;
            }else{
                res += 1;
            }
        }else if(n%i == 0){
            ll c = n;
            while(c % i == 0) c /= i;
            //cout << i << "," << c << endl;
            if(c%i == 1) ++res;
        }
    }
    
    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int N;
    cin >> N;
    vector<int> P(N);
    int m = 1e9, ans = 0;
    REP(i, N) {
        int tmp;
        cin >> tmp;
        if(m >= tmp) ans++;
        if(m > tmp) m = tmp;
    }

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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
struct food{
	int a;
	int b;
	int sum;
}s[100000];
int sum_comp(const food &x,const food &y)
{
	if(x.sum>y.sum)  return 1;
	if(x.sum<y.sum)  return 0;
	return 0;
}
int main() 
{
	int n,i;
	long long sum1=0,sum2=0;
	cin>>n;
for(i=0;i<n;i++)
{
	cin>>s[i].a;
	cin>>s[i].b;
}
for(i=0;i<n;i++)
s[i].sum=s[i].a+s[i].b;
sort(s,s+n,sum_comp);
if(n%2==0)
{
	for(i=0;i<n-1;i=i+2)
	{
		sum1=sum1+s[i].a;
	}
	for(i=1;i<n;i=i+2)
	{
		sum2=sum2+s[i].b;
	}
}
else
{
	for(i=0;i<n;i=i+2)
	{
		sum1=sum1+s[i].a;
	}
	for(i=1;i<n-1;i=i+2)
	{
		sum2=sum2+s[i].b;
	}
}
	cout<<sum1-sum2<<endl;
	
	
return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<cstring> 
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm> 
#include<limits.h>
using namespace std;

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;

const int limit = 1e5+1;

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

    int dp[3][limit];

    dp[0][0]=dp[1][0]=dp[2][0]=0;
    for(int i=1;i<=n;i++){
        int a,b,c;cin >> a >> b >> c;
        dp[0][i] = max(dp[1][i-1],dp[2][i-1]) + a;
        dp[1][i] = max(dp[2][i-1],dp[0][i-1]) + b;
        dp[2][i] = max(dp[0][i-1],dp[1][i-1]) + c;
    }
    p(max(dp[0][n],max(dp[1][n],dp[2][n])))
}

Measured memory_bytes: 1408
#include<stdio.h>
int main(){
int H,W;
int h,w;
while(1){
scanf("%d%d",&H,&W);
if(H == 0 && W == 0)break;
   for(h = 0;h < H;h++){ 
   for(w = 0;w < W;w++)putchar('#');
    putchar('\n');}
putchar('\n');}
return 0;
}  



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

int main(void){
	string S;
	cin >> S;
	
	int N=S.size();
	
	for(int i=0 ; i<(N-1)/2 ; i++){
		if((S[i]==S[N-i-1])&&(S[i]==S[(N+1)/2+i])){
			if(i==(N-3)/2)	cout<<"Yes"<<endl;
		}
		else {
			cout << "No"<<endl;
			break;
	}	
    }

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
int main() {
	int N;
	cin >> N;
	vector<P> v;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		v.emplace_back(a, i);
	}
	sort(v.begin(), v.end());
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		if (i % 2 != v[i].second % 2) cnt++;
	}
	cout << cnt / 2 << endl;
}

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

int main() {
    int n;
    cin >> n;
    double sum = 0;
    rep(i,n) {
        int a;
        cin >> a;
        sum += 1.0/a;
    }
    printf("%.10f\n", 1/sum);
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String	O = sc.next(),E=sc.next();
		char[] array = new char[E.length()+O.length()+1];
		int count=0;
		char[] z = new char[1];

		for(int i=1;i<E.length()*2;i+=2) {
			array[i] = E.charAt(count);
			count++;
		}
		count=0;
		for(int i=0;i<O.length()*2;i+=2) {
			array[i] = O.charAt(count);
			count++;
		}
		for(int i=0;i<array.length;i++) {
			if(array[i] != z[0])System.out.print(String.valueOf(array[i]));
		}
	}

	public static int sample() {
		return 1;
	}

}


Measured memory_bytes: 21332
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  int H[100010];
  int dp[100010];
  dp[0] = 0;

  cin >> N;
  for(int i=0;i<N;++i){
    cin >> H[i];
    if(i>=2){
      dp[i] = min(dp[i-2]+abs(H[i]-H[i-2]),dp[i-1]+abs(H[i]-H[i-1]));
    }else if(i>=1){
      dp[i] = dp[i-1]+abs(H[i]-H[i-1]);
    }
  }
  cout << dp[N-1] << endl;
}


Measured memory_bytes: 1024
# start 21:14
a, b = [int(item) for item in input().split()]

# 素因数リスト
import math
def factor(num):
    divisor_list = [1]
    divisor = 2
    max_prime = int(math.sqrt(num))
    while max_prime >= divisor:
        if num % divisor == 0:
            divisor_list.append(divisor)
            num //= divisor

        else:
            divisor += 1
    divisor_list.append(num)
    return divisor_list

def gcd(a, b):
    if b == 0: return a
    return gcd(b, a % b)

cd_list = set(factor(gcd(a, b)))

print(len(cd_list))

Measured memory_bytes: 3064
try:
    X_s,Y_s,Z_s = input().split(' ')
    X=int(X_s)
    Y=int(Y_s)
    Z=int(Z_s)
    
    if X>=1 and X<=100 and Y>=1 and Y<=100 and Z>=1 and Z<=100:
        
        A=X
        B=Y
        C=Z
        
        temp=B
        B=A
        A=temp
        
        temp=C
        C=A
        A=temp
        
        print(A,'',B,'',C)
        
except Exception as e:
    print(e)

Measured memory_bytes: 9000
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
#include<stdio.h>
#include <queue>
#include <iomanip>
#include <float.h>
#include <set>
#include<functional>
#include <stack>
#include <time.h>
using namespace std;
int  gcd(int a,int b) {
	if (a < b) gcd(b, a);
	int r;
	while ((r = a%b)) {
		a = b;
		b = r;
	}
	return b;
}
long long lcm(long long a, long long b) {
	return a / gcd(a, b) * b;
}
long long nibun(int t,long long bound) {
	long long lb = 1;
	long long ub = 1000000000;
	while (ub - lb > 1) {
		long long mid = (ub + lb) / 2;
		long long tmp = 1;
		for (int i = 0; i < t; i++) {
			tmp *= mid;
			if (tmp > bound)break;
		}
		if (tmp > bound)ub = mid;
		else lb = mid;
	}
	return lb;
}
long long nibun2(int t, long long bound) {
	long long lb = 1;
	long long ub = 1000000000;
	while (ub - lb > 1) {
		long long mid = (ub + lb) / 2;
		long long tmp = 1;
		for (int i = 0; i < t; i++) {
			tmp *= mid;
			if (tmp >= bound)break;
		}
		if (tmp >= bound)ub = mid;
		else lb = mid;
	}
	return lb;
}
long long inf = 998244353;
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, c;
	cin >> a >> b >> c;
	cout << b + min(a + b+1, c);
}

Measured memory_bytes: 892
#include<iostream>
using namespace std;
int main(){
int x,y,w,i=0,h,count=0;
double a=0,b;
  cin>>w>>h>>x>>y;
  if(w/2==x&&w%2==0&&h/2==y&&h%2==0){a=(float)w*h;count++;}
  else{a=(float)w*h;}
  if(a>=w*h)a/=(float)2;
  cout<<a<<" "<<count;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0; i<n; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  vector<int> c;
  int count = 0;
  for(int i=0; i<n; i++) {
    if(count == 0) {
      count++;
    } else if(a.at(i) == a.at(i-1)) {
      count++;
    } else if(a.at(i) == a.at(i-1)+1) {
      c.push_back(count);
      count = 1;
    } else if(a.at(i) == a.at(i-1)+2) {
      c.push_back(count);
      c.push_back(0);
      count = 1;
    } else {
      c.push_back(count);
      c.push_back(0);
      c.push_back(0);
      count = 1;
    }
  }
  c.push_back(count);
  int m = c.size();
  int ans = 0;
  if(m < 3) {
    for(int x : c) {
      ans += x;
    }
    cout << ans << endl;
    return 0;
  }
  int temp;
  for(int i=2; i<m; i++) {
    temp = c.at(i) + c.at(i-1) + c.at(i-2);
    ans = max(ans,temp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1276
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
#define ll long long
int main (){
    double r, g;
    cin >> r >> g;
    cout << (g-r)*2+r << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ll N;
    cin >> N;

    ll sum = 0;
    ll BA = 0, B = 0, A = 0;
    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        for (int j = 1; j < s.size(); j++) {
            if (s[j - 1] == 'A' && s[j] == 'B') {
                sum++;
            }
        }
        if (s.front() == 'B' && s.back() == 'A') {
            BA++;
        } else if (s.front() == 'B') {
            B++;
        } else if (s.back() == 'A') {
            A++;
        }
    }

    if (BA > 1) {
        sum += BA - 1;
        BA = 1;
    }

    if (BA == 1 && A != 0 && B != 0) {
        sum += 2;
        BA--;
        A--;
        B--;
    }

    sum += min(A, B);
    ll rest = abs(B - A);
    sum += min(BA, rest);
    cout << sum << endl;
}

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

using namespace std;

int cnt_digits(int x) {
  int ret = 0;
  while (x > 0) {
    ret++;
    x /= 10;
  }
  return ret;
}

int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (cnt_digits(i) & 1) {
      ans++;
    }
  }
  cout << ans;
  return 0;
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;

int n, k;
vector<ll> vs;

vector<ll> memo;

ll dfs(int index, ll height, int color) {
	if (index == n) {
		if (color < k) return INF;
		return 0;
	}
	ll a = INF;
	if (height < vs[index]) {
		a = min(a, dfs(index + 1, vs[index], color + 1));
	}
	else {
		a = min(a, dfs(index + 1, height, color));		
		ll add = height + 1 - vs[index];
		a = min(a, dfs(index + 1, height+1, color+1) + add);
	}
	memo[index] = a;
	return a;
}

int main() {
	int n;
	cin >> n;
	vector<P> vs(n);
	rep(i, n) {
		cin >> vs[i].first >> vs[i].second;
	}
	vector<vector<double>> ds(n, vector<double>(n));
	rep(i, n) {
		rep(j, n) {
			double dx = vs[i].first - vs[j].first;
			double dy = vs[i].second - vs[j].second;
			double d = sqrt(dx * dx + dy * dy);
			ds[i][j] = d;
		}
	}
	vector<int> visit;
	rep(i, n) visit.push_back(i);

	double sum = 0;
	double div = 0;
	do {
		double a = 0;
		rep(i, n - 1) {
			a += ds[visit[i]][visit[i + 1]];
		}
		sum += a;
		div++;
	} while (std::next_permutation(visit.begin(), visit.end()));
	cout << fixed << setprecision(10);
	cout << sum/div << endl;
	return 0;
}


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

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public class View
	{
		public int Index {get;set;}
		public long Height {get;set;}
		public List<int> Roots {get;set;}
	}
	public static void Main(string[] args)
	{
		var p = Input().ToInt();
		var n = p[0];
		var m = p[1];
		var q = Input();
		var h = new long[n];
		var v = new View[n];
		for(int i = 0; i < n; i++)
		{
			h[i] = q[i].ToLong();
			v[i] = new View(){Index=i, Height = h[i], Roots = new List<int>()};
		}
		for(int i = 0; i < m; i++)
		{
			p = Input().ToInt(-1);
			v[p[0]].Roots.Add(p[1]);
			v[p[1]].Roots.Add(p[0]);
			//u.Unite(p[0], p[1]);
		}
		long wa = 0;
		for(int i = 0; i < n; i++)
		{
			long maxHeight = 0;
			foreach(var k in v[i].Roots)
			{
				maxHeight = Math.Max(maxHeight, v[k].Height);
			}
			if(maxHeight < v[i].Height)
				wa++;
		}
		Console.WriteLine(wa);
		
	}
	
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 66180
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int n,k,x,y;
  cin>>n>>k>>x>>y;
  int som=0;
  for(int i=0;i<k;i++){
    if(n<=i){
      break;
    }
    som+=x;
  }
  for(int i=0;i<n-k;i++){
    som+=y;
  }
  cout<<som<<"\n";
  return(0);
}


Measured memory_bytes: 256
#include <iostream>
#define LIMIT 1000000000000000000

using namespace std;

int main(){
    int n;
    unsigned long long a, ans = 1;
    bool overflow = false;

    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a;
        if(!a || !ans || a <= LIMIT / ans){
            ans *= a;
        }
        else{
            overflow = true;
        }
    }
    
    if(!overflow || ans == 0){
        cout << ans << endl;
    }
    else{
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 3504
/*input 
2213
*/
#include <bits/stdc++.h>
using namespace std;

typedef double db;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;

#define FOR(i, l, r) for(int i = l; i <= r; ++i)
#define FORD(i, l, r) for(int i = l; i >= r; --i)
#define REP(i, r) for(int i = 0; i < int(r); ++i)
#define REPD(i, r) for(int i = int(r)-1; i >= 0; --i)
#define fi first
#define se second
#define sz size
#define endl '\n'
#define debug(x) cout << #x << " = " << x << endl;

const int Nmax = 1e6 + 10;
const ll inf = 1e9;
const db _eps = 1e-5;

int a[5], b;

bool check() {
	if (a[1] == a[2] && a[2] == a[3]) return true;
	if (a[2] == a[3] && a[3] == a[4]) return true;
	return false;
}

int main() {
	cin >> b;
	int cnt = 1;
	while (b != 0) {
		a[cnt] = b%10;
		b /= 10;
		cnt++;
	}
	cout << (check() == true ?  "Yes" : "No");
}

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1001001001;

const int mod = 1000000007;

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

    vector<int> ps(n);
    rep(i, n) {
        cin >> ps[i];
    }

    int count = 0;
    rep(i, n - 2) {

        int a = ps[i];
        int b = ps[i + 1];
        int c = ps[i + 2];

        if ((a < b && b < c) || (c < b && b < a)) {
            count++;
        }
    }

    cout << count << endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int ans[10001];
int32_t main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	cin >> n;
	for(int x=1; x<=100; x++) {
		for(int y=1; y<=100; y++) {
			for(int z=1; z<=100; z++) {
				int v = x*x+y*y+z*z+x*y+y*z+z*x;
				if(v <= 10000)
					ans[v]++;
			}
		}
	}
	for(int i=1; i<=n; i++) {
		cout << ans[i] << '\n';
	}
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define forr(i,n) for(int i=n;i>=0;i--)
#define all(x) x.begin(), x.end()
const int MAXN = 1e5 +5;
const LL m = 1e9+7;

void fio(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

vector<LL> pr;
LL phi[MAXN];

LL po(LL a, LL n){
	if(n==0) return 1;
	LL an = po(a,n/2);
	an = (an*an)%m;
	if(n&1) an = (an*a)%m;
	return an;
}

int main(){
  fio();
  LL n,k; cin>>n>>k;
  LL an = po(k,n);
  for(LL i=2; i<=k; i++){
  	if(phi[i]==0){
  		pr.pb(i);
  		phi[i] = i-1;
  	}
  	an = (an + po(k/i,n)*phi[i])%m;
  	for(auto p:pr){
  		if(i*p>k) break;
  		if(i%p==0){
  			phi[i*p] = (p*phi[i])%m;
  		}
  		else{
  			phi[i*p] = (phi[i]*phi[p])%m;
  		}
  	}
  }
  cout<<an<<endl;
  return 0;
}

Measured memory_bytes: 4504
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
 
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpi;
typedef vector<pair<ll, ll> > vpl;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, c;
  cin >> a >> b >> c;
  if(a+b == c ||
     a+c == b ||
     b+c == a){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
	return 0;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int>L(n);
	for(auto&i:L)cin>>i;
	sort(L.begin(),L.end());
	int ans=0;
	for(int i=0;i<n-2;++i){
		for(int j=i+1;j<n-1;++j){
			int low=abs(L.at(i)-L.at(j)),
				high=L.at(i)+L.at(j);
				auto left=upper_bound(L.begin()+j+1,L.end(),low),
					 right=lower_bound(L.begin()+j+1,L.end(),high);
				ans+=right-left;
		}
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <cstdio>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define int long long
using namespace std;

signed main() {
    int n;
    int ans = 0;
    int count;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        if (i % 2 == 1) {
            count = 0;
            for (int j = 1; j <= i; j++) {
                if (i % j == 0) {
                    count++;
                }
            }
            if (count == 8) {
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import random
import copy


def main():
    D = int(input())
    c = list(map(int, input().split()))
    s = [list(map(int, input().split())) for _ in range(D)]

    t = [0] * D

    # 貪欲法でまず求める
    penalty = copy.deepcopy(c)
    for i in range(D):
        ind = 0
        tmp = 0
        for j in range(26):
            if penalty[j] + s[i][j] > tmp:
                tmp = penalty[j] + s[i][j]
                ind = j
        penalty[ind] = 0
        t[i] = ind + 1
        for j in range(26):
            penalty[j] += c[j]

    # 適当なtをスワップしてスコアが伸びればそれを採用する
    ans = calc(s, c, t)
    rand = list(range(365))
    for i in range(500):
        swap = random.sample(rand, 2)
        t[swap[0]], t[swap[1]] = t[swap[1]], t[swap[0]]
        tmp = calc(s, c, t)
        if tmp < ans:
            # 元に戻す
            t[swap[0]], t[swap[1]] = t[swap[1]], t[swap[0]]
        else:
            ans = tmp
    return t


def output(t):
    for tt in t:
        print(tt)


def calc(s, c, t):
    d = [0] * 26

    ans = 0
    days = 0
    for tt in t:
        for i in range(26):
            d[i] += 1
        d[tt-1] = 0
        ans += s[days][tt-1]
        for i in range(26):
            ans -= d[i] * c[i]
        days += 1
        # print(ans)

    return ans


if __name__ == "__main__":
    t = main()
    output(t)


Measured memory_bytes: 10056
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

int group(int x) {
	if (x == 2) return 1;
	if (x == 4 || x == 6 || x == 9 || x == 11) return 2;
	return 3;
}

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

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

using namespace std;

long long INF = 1000000000000000000;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<long long> a(n);
    long long ans = 1;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        if (a[i] == 0) {
            cout << 0 << '\n';
            return 0;
        }
    }
    for (int i = 0; i < n; i++) {
        if (ans > (INF / a[i])) {
            cout << -1 << '\n';
            return 0;
        } else {
            ans *= a[i];
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3996
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

/*
カップゲーム

3 つのカップがふせて置かれています。カップの置かれている場所を、順に A,B,C と呼ぶことにします。
最初は A に置かれているカップの中にボールが隠されているとします。
カップの位置を入れ替えると、中に入っているボールも一緒に移動します。
入れ替える２つのカップの位置を読み込んで、最終的にどの場所のカップにボールが隠されているかを出力するプログラムを作成してください。

Input
　入れ替える２つのカップの位置が順番に複数行にわたり与えられます。
　各行に、入れ替える２つのカップの位置を表す文字（A, B, または C）がカンマ区切りで与えられます。
　入れ替える操作は 50 回を超えません。

Output
　ボールが入っているカップの場所（A, B, または C）を１行に出力します。

Sample Input
B,C
A,C
C,B
A,B
C,B

Output for the Sample Input
A

*/

/**
 * カップゲーム
 *
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0047
 */
public class Main {

	public static void main(String[] args) throws Exception {
		// キー：カップ名、値：ボールが入っているかどうか　最初はAに入っている
		Map<String, Boolean> cups = new HashMap<>();
		cups.put("A", true);
		cups.put("B", false);
		cups.put("C", false);

		try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
			reader.lines().map(line -> line.split(",")).forEach(pair -> {
				// 二つを入れ替える
				boolean temp = cups.get(pair[1]);
				cups.put(pair[1], cups.get(pair[0]));
				cups.put(pair[0], temp);
			});

			// 入っているカップ（値がtrueのもの）を出力する
			cups.entrySet().forEach(e -> {
				if (e.getValue()) {
					System.out.println(e.getKey());
				}
			});
		}
	}

}



Measured memory_bytes: 30936
#include <iostream>
using namespace std;
typedef long long ll;

struct Edge{
	ll cost;
	int from,to;
	Edge(){}
	Edge(int from,int to,ll cost): from(from),to(to),cost(cost){}
};

int n,m;
Edge e[2005];
ll d[1005];

bool bellman_ford(){
	for(int i=0;i<1005;i++){
		d[i]=1e18;
	}
	d[0]=0;
	for(int i=0;i<2*n;i++){
		for(int j=0;j<m;j++){
			if(d[e[j].from]!=1e18 && d[e[j].to]>d[e[j].from]+e[j].cost){
				d[e[j].to]=d[e[j].from]+e[j].cost;
				if(i>=n-1&&e[j].to==n-1) return true;
			}
		}
	}
	return false;
}

int main(){
	cin >> n >> m;
	for(int i=0;i<m;i++){
		int a,b; ll c;
		cin >> a >> b >> c;
		e[i]=Edge(a-1,b-1,-c);
	}
	if(bellman_ford()){
		cout << "inf" << endl;
	}
	else{
		cout << -d[n-1] << endl;
	}
}

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

int main() {
    string a,b;
    cin >> a >> b;
    string s = a+b;
    int ans = stoi(s);
    int ans1 = sqrt(ans);
    if(ans1*ans1 == ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}



Measured memory_bytes: 256
n = int(input())
sp = []
for i in range(n):
    sp.append(list(map(str, input().split())))

spi = []
for i in range(n):
    spi.append([sp[i][0], -1*int(sp[i][1]), i])

spi.sort()

for _spi in spi:
    print(_spi[2]+1)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define pb push_back 
using namespace std;

const int maxn=1e5+7;
typedef long long ll;

int n,m,ans;
int a[maxn];
vector<int>e[maxn];
int flag;

void dfs(int x,int pre)
{
	a[x]=1;
	int len=e[x].size();
	int f=0;
	for(int i=0;i<len;++i)
	{
		int v=e[x][i];
		if(v!=pre)
		{
			dfs(v,x);
			if(flag) f++,flag=0;
			a[x]+=a[v];
		}
		
	}
	if(f>1)
	{
		printf("First");
		exit(0);
	}
	
	
	if(a[x]%2)
	{
		flag=1;
	}
}

int main()
{
	int i,j,k;
	scanf("%d",&n);
	for(i=1;i<n;++i)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		e[x].pb(y);
		e[y].pb(x);
	}
	if(n%2)
	{
		printf("First");
		return 0;
	}
	
	dfs(1,0);
	
	printf("Second");
	
	return 0;
}


Measured memory_bytes: 6144
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <unordered_set>
#include <queue>
#include <boost/math/constants/constants.hpp>
#include <boost/math/common_factor_rt.hpp>
 
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, n, m) for(int i=n; i<m; ++i)
 
int main() {
  ll X, Y, A, B, C, tmp;
  cin >> X >> Y >> A >> B >> C;
  vector<ll> a,b,c,esc;
  rep(i,A) cin >> tmp, a.push_back(tmp);
  rep(i,B) cin >> tmp, b.push_back(tmp);
  rep(i,C) cin >> tmp, c.push_back(tmp);
  sort(a.begin(), a.end(), greater<ll>());
  sort(b.begin(), b.end(), greater<ll>());
  sort(c.begin(), c.end());
  
  vector<ll> merge1(X), merge2(Y);
  copy(a.begin(), a.begin()+X, merge1.begin());
  copy(b.begin(), b.begin()+Y, merge2.begin());
  merge1.insert(merge1.end(), merge2.begin(), merge2.end());
  sort(merge1.begin(), merge1.end(), greater<ll>());
  
  while(merge1.back()<c.back() && (!c.empty())){
    esc.push_back(c.back());
    merge1.pop_back();
    c.pop_back();
  }
  
  ll sum = 0;
  rep(i, merge1.size()) sum+=merge1[i];
  rep(i, esc.size()) sum+=esc[i];
  cout << sum << endl;
}

Measured memory_bytes: 6452