akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::*;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    return ret;
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.is_err() || res.ok().unwrap() == 0 || u8b[0] <= ' ' as u8 {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = std::string::String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}
fn parse<T: std::str::FromStr>(s: &str) -> T { s.parse::<T>().ok().unwrap() }

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { parse(&get_word()) }

fn main() {
    let n: usize = get();
    let m: usize = get();
    let a: Vec<usize> = (0 .. m).map(|_| get()).collect();
    let mut e = 0;
    for i in 0 .. m {
        e += a[i] / 2;
    }
    if e < n - 1 - n / 2 {
        println!("Impossible");
        return;
    }
    let mut odd = Vec::new();
    let mut rest = Vec::new();
    for a in a {
        if a % 2 == 1 {
            odd.push(a);
        } else {
            rest.push(a);
        }
    }
    let mut ans1 = vec![0; m];
    let mut ans2;
    if n % 2 == 1 {
        // a[i] must have exactly one odd element
        assert_eq!(odd.len(), 1);
        let odd = odd[0];
        ans2 = vec![0; m + 1];
        ans1[0] = odd;
        ans2[0] = odd - 1;
        for i in 0 .. m - 1 {
            ans1[i + 1] = rest[i];
            ans2[i + 1] = rest[i];
        }
        ans2[m] = 1;
    } else {
        assert!(odd.len() == 0 || odd.len() == 2);
        if odd.len() == 0 {
            ans1 = rest;
            ans2 = vec![0; m + 1];
            ans2[0] = 1;
            for i in 0 .. m {
                ans2[i + 1] = ans1[i];
            }
            ans2[m] -= 1;
        } else {
            ans2 = vec![0; m];
            ans1[0] = odd[0];
            ans2[0] = odd[0] + 1;
            for i in 0 .. m - 2 {
                ans1[i + 1] = rest[i];
                ans2[i + 1] = rest[i];
            }
            ans2[m - 1] = odd[1] - 1;
            ans1[m - 1] = odd[1];
        }
    }
    ans2 = ans2.into_iter().filter(|&x| x != 0).collect();
    for i in 0 .. ans1.len() {
        print!("{}{}", ans1[i], if i + 1 == ans1.len() { "\n" } else { " " });
    }
    println!("{}", ans2.len());
    for i in 0 .. ans2.len() {
        print!("{}{}", ans2[i], if i + 1 == ans2.len() { "\n" } else { " " });
    }
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	double L; cin >> L;
	cout << pow(L/3, 3) << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 384
import math
n = int(input())
s = []
for i in range(n):
    a = input()
    a = [i for i in a]
    a = sorted(a)
    s.append(a)
count = 0
s = sorted(s)
p = 0
try:
    for i in range(len(s)):
        if s[i]==s[i+1]:
            p+=1
        else:
            count+=sum(list(range(p+1)))
            p=0
except:
    count+=sum(list(range(p+1)))
print(count)

Measured memory_bytes: 28060
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n,m;
vector<int> way[maxn];
int sz,bad;
int num[maxn];
void dfs(int u) {
    sz++;
    for(auto v : way[u]) {
        if(num[v]==num[u]) bad = 1;
        if(num[v]!=-1) continue;
        num[v] = !num[u]; dfs(v);
    }
}
int main() {
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++) {
		int u,v; scanf("%d%d",&u,&v);
		way[u].push_back(v); way[v].push_back(u);
	}
	for(int i=1;i<=n;i++) num[i] = -1;
	long long indy = 0, cnt0 = 0, cnt1 = 0;
	for(int u=1;u<=n;u++) {
        if(num[u]!=-1) continue;
        bad = 0; sz = 0;
        num[u] = 0; dfs(u);
        if(sz==1) indy++;
        else if(!bad) cnt0++;
        else cnt1++;
	}
//	printf("%lld %lld %lld\n",indy,cnt0,cnt1);
	long long res = 2LL*indy*n - indy*indy + 2LL*cnt0*cnt0 + 2LL*cnt0*cnt1 + cnt1*cnt1;
	printf("%lld",res);
}


Measured memory_bytes: 9088
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
  double a[2],b[2],c[2];
  int n;
  cin >>n;
  while(n--){
    cin>>a[0]>>a[1]>>b[0]>>b[1]>>c[0]>>c[1];
    b[0]-=a[0];
    b[1]-=a[1];
    c[0]-=a[0];
    c[1]-=a[1];
    double m[2][2],ans[2],rev[2][2];
    m[0][0] = 2*b[0];
    m[0][1] = 2*b[1];
    ans[0] = b[0]*b[0]+b[1]*b[1];
    m[1][0] = 2*c[0];
    m[1][1] = 2*c[1];
    ans[1] = c[0]*c[0]+c[1]*c[1];
    double det = m[0][0]*m[1][1]-m[1][0]*m[0][1];
    rev[0][0] = m[1][1]/det;
    rev[1][0] = -m[1][0]/det;
    rev[0][1] = -m[0][1]/det;
    rev[1][1] = m[0][0]/det;
    double x = ans[0]*rev[0][0]+ans[1]*rev[0][1];
    double y = ans[0]*rev[1][0]+ans[1]*rev[1][1];
    double r = sqrt(x*x+y*y);
    printf("%.03lf %.03lf %.03lf\n",x+a[0],y+a[1],r);
  }
  return 0;
}

Measured memory_bytes: 0
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define ll long long int
#define vec vector
#define forn(a) for(ll a=0; a<n; a++)
#define all(x) x.begin(), x.end()
#define deb(x) cerr<<#x<<" = "<<x<<endl

using namespace std;

int main() {
    IOS;

    int a, b; cin>>a>>b;
    cout<<max(a+b, max(a-b, a*b))<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
const int MAX = 510000;

long long ans=0;
long long fac[MAX], finv[MAX], inv[MAX];

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

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

int main(){
  long long n,m,k;
  cin>>n>>m>>k;
  
  for(int i=0;i<n;i++){
    ans+=i*(n-i)*m*m%mod;
    ans%=mod;
  }
  for(int i=0;i<m;i++){
    ans+=i*(m-i)*n*n%mod;
    ans%=mod;
  }
  
  COMinit();
  ans*=COM(n*m-2,k-2)%mod;
  ans%=mod;

  cout<<ans<<endl;

  return(0);
}


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

int main() {
  int N;
  while (cin >> N, N) {
    auto s = vector<int>(N, 0);
    for (int i = 1; i < N; ++i) s[i] = s[i - 1] + i;
    int ans = 0;
    for (int l = 0; l < N; ++l) {
      for (int r = l + 1; r < N; ++r) {
        if (s[r] - s[l] == N) ++ans;
      }
    }
    cout << ans << endl;
  }
  return 0;
}



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

int main(){
    int n, m; cin >> n >> m;
    map<int,int> mp;
    int a,b;
    rep(i,n) mp[i] = 0;
    rep(i,m){
        cin >> a >> b;
        mp[a-1]++;
        mp[b-1]++;
    }

    for(auto x:mp){
        cout << x.second << endl;
    }

}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);
        while(true) {
            int m = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();
            if(m == -1 && f == -1 && r == -1) break;
            if(m == -1 || f == -1) { System.out.println('F'); continue; }
            if(m + f >= 80) { System.out.println('A'); continue; }
                if(m + f >= 65) { System.out.println('B'); continue; }
                if(m + f >= 50) { System.out.println('C'); continue; }
            if(m + f >= 30) {
                    if(r >= 50) System.out.println('C');
                else System.out.println('D');
                continue;
            }
            System.out.println('F');
             
        }
    }
}



Measured memory_bytes: 26364
a[4],b[4];main(i,j,h,l){for(;~scanf("%d%d%d%d%d%d%d%d",a,a+1,a+2,a+3,b,b+1,b+2,b+3);printf("%d %d\n",h,l))for(i=h=l=0;i<4;i++)for(j=0;j<4;j++)if(a[i]==b[j])i==j?h++:l++;exit(0);}

Measured memory_bytes: 596
def main():
    A, V = (int(i) for i in input().split())
    B, W = (int(i) for i in input().split())
    T = int(input())
    if A == B:
        print("YES")
    elif V <= W:
        print("NO")
    elif abs(A-B) <= (V-W)*T:
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    main()


Measured memory_bytes: 61768
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	double sum = 0;
	for( int i = 0; i < n; ++i ){
		double k; cin >> k;
		string s; cin >> s;
		if( s == "BTC" ){
			k *= 380000.0;
		}
		sum += k;
	}
	cout << fixed << setprecision(5) << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

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; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<60;
constexpr double eps = (1e-9);

using P = pair<int, int>;

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

  int n, m;
  cin >> n >> m;
  vector<vector<int>> e(n);
  rep(i, m) {
    int u, v; cin >> u >> v; u--; v--;
    e[u].push_back(v);
  }

  int s, t; cin >> s >> t; s--; t--;

  vector<vector<int>> d(n, vector<int>(3, INF));
  queue<P> q;
  q.push({s, 0});
  d[s][0] = 0;

  while (!q.empty()) {
    int v = q.front().first;
    int l = q.front().second;
    q.pop();
    for (auto& u : e[v]) {
      int nl = (l + 1) % 3;
      if (d[u][nl] != INF) continue;
      d[u][nl] = d[v][l] + 1;
      q.push({u, nl});
    }
  }

  if (d[t][0] == INF) cout << -1 << endl;
  else cout << d[t][0] / 3 << endl;

  return 0;
}


Measured memory_bytes: 14264
#include <stdio.h>

int main(void)
{
	char a[100],b[100],c[100];
	int i=0,an=0,bn=0,cn=0;
	scanf("%s%s%s",a,b,c);
	while(1){
		if(i==0){
			if(a[an]=='\0')break;
			else if(a[an]=='b')i=1;
			else if(a[an]=='c')i=2;
			an++;
		}
		else if(i==1){
			if(b[bn]=='\0')break;
			else if(b[bn]=='a')i=0;
			else if(b[bn]=='c')i=2;
			bn++;
		}
		else{
			if(c[cn]=='\0')break;
			else if(c[cn]=='a')i=0;
			else if(c[cn]=='b')i=1;
			cn++;
		}
	}
	puts(i==0?"A":i==1?"B":"C");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <map>
using namespace std;

vector<int> nextstate(int x_)
{
    vector<int> x(8);
    int cnt = 0;
    while(x_){
        x[7-cnt]=x_%10;
        cnt++;
        x_ /= 10;
    }
    if(cnt==7)x[0]=0;

    vector<int> res;
    int d[4]={1,-1,4,-4};
    int id;
    for(int i=0;i<8;i++)if(x[i]==0){id=i; break;}
    for(int i=0;i<4;i++){
        int nid = id+d[i];
        if(nid>=0 && nid<8){
            if(d[i]==-1&&nid==3 || d[i]==1&&nid==4)continue;
            vector<int> tmp = x;
            int tmp_ = 0;
            swap(tmp[id], tmp[nid]);
            for(int i=0;i<8;i++){
                tmp_ *= 10;
                tmp_ += tmp[i];
            }
            res.push_back(tmp_);
        }
    }
    return res;
}

// vector<int> s;
int s;

void input()
{
    int t;
    for(int i=0;i<8;i++){
        cin>>t;
        s *= 10;
        s += t;
        // s.push_back(t);
    }
}

map<int, int> known;

void bfs(int s)
{
    queue<int> que;
    que.push(s);
    known[s] = 0;
    while(!que.empty()){
        int cur = que.front();
        que.pop();
        vector<int> nexts = nextstate(cur);
        // cout<<"*"<<cur<<endl;
        for(int i=0;i<nexts.size();i++){
            if(known.find(nexts[i])==known.end()){
                known[nexts[i]] = known[cur] + 1;  
                que.push(nexts[i]);
                // cout<<nexts[i]<<endl;
            }
        }
    }
    return;
}


int main()
{
    // input();
    // vector<int> res = nextstate(s);
    // cout<<res.size()<<endl;
    // for(int i=0;i<res.size();i++){
    //     cout<<res[i]<<endl;
    // }
    bfs(1234567);
    vector<int> in(8);
    while( 8 == scanf("%d %d %d %d %d %d %d %d",
		&in[0],&in[1],&in[2],&in[3],&in[4],&in[5],&in[6],&in[7]) )
	{
		int tmp = 0;
        for(int i=0;i<8;i++){
            tmp *= 10;
            tmp += in[i];
        }
        cout<<known[tmp]<<endl;
	}

    return 0;
}



Measured memory_bytes: 4180
a,b,c,x,y=gets.split.map(&:to_i)
if(x>y)
  t=a;a=b;b=t
  t=x;x=y;y=t
end
c+=c

  p [a*x+y*[b,c].min,c*x+(y-x)*[b,c].min].min



Measured memory_bytes: 1788
import math

def is_prime(x):
    for i in range(2, int(math.sqrt(x)+1)):
        if x % i == 0:
            return False
    return True

x = int(input())

if x == 2:
    print(2)
else:
    while True:
        if is_prime(x):
            print(x)
            break
        else:
            x += 1

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
main()
{
	int n,m,x;
	cin>>n>>m>>x;
	int arr[n];
	memset(arr,0,sizeof(arr));
	int c1=0,c2=0;
	for(int i=0;i<m;i++)
	{
		int ind;
		cin>>ind;
		if(ind<x)
		c1++;
		else
		c2++;
	}
	cout<<min(c1,c2)<<endl;
	return 0;
}


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

int main(){
    string s; cin >> s;
    map<long long, long long> m;
    m[0] = 1;
    reverse(s.begin(), s.end());
    long long a = 0, b = 1;
    for(int i = 0; i < s.size(); i++){
        a = (a + b * (s.at(i) - '0')) % 2019;
        b *= 10;
        b %= 2019;
        m[a]++;
    }
    long long ans = 0;
    for(auto p: m){
        ans += p.second*(p.second-1)/2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3716
//g++ -std=c++11
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;

typedef pair <int, int> pi;
typedef pair <ll, ll> pl;
typedef pair <ld, ld> pd;

typedef vector <int> vi;
typedef vector <ll> vl;
typedef vector <ld> vd;
typedef vector <pi> vpi;
typedef vector <pl> vpl;

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define ins insert

const int INF = 1000000000;
const int MAXN = 200000;
const int MOD = 1000000007;
const char nl = '\n';

int main() {

    std::ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll a,b;
    char c;
    int d;

    cin >> a >> b >> c >> d;
    b*=100, b+=d;
    ll x = (a*b)/100;     
    cout << x << nl;
    return 0;
}

Measured memory_bytes: 3632
import sys
input = sys.stdin.readline

N,W=map(int,input().split())
S=[list(map(int,input().split())) for i in range(N)]

from collections import defaultdict
DP = defaultdict(int)
DP[0]=0

for w,v in S:
    for w2 in sorted(DP.keys(),reverse=True):
        if w+w2<=W:
            DP[w+w2]=max(DP[w+w2],DP[w2]+v)

print(max(DP.values()))

Measured memory_bytes: 3700
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
      String S = sc.next();
      int Q = sc.nextInt();
      ArrayList<String> bf = new ArrayList<>();
      ArrayList<String> af = new ArrayList<>();
      boolean asc =true;
      int Ti;
      int Fi;
      String Ci;
	for(int i=0;i<Q;i++){
      Ti = sc.nextInt();
      if(Ti==1){
        asc = !asc;
        continue;
      }
      Fi = sc.nextInt();
      if(asc){
        if(Fi==1){
          bf.add(sc.next());
        }else{
          af.add(sc.next());
        }
      }else{
        if(Fi==2){
          bf.add(sc.next());
        }else{
          af.add(sc.next());
        }
      }
    }
      String str ="";
if(asc){
  Collections.reverse(bf);
    str+=String.join("", bf);
  str+=S;
    str+=String.join("", af);
}else{
    Collections.reverse(af);
  str+=String.join("", af);
  String[] st = S.split("");
  List<String> sta = Arrays.asList(st);
  Collections.reverse(sta);
  str+=String.join("", sta);
  str+=String.join("", bf);
}
      System.out.println(str);


    }
  
  private static long lcm(long m, long n) {
    return m * n / gcd(m, n);
}
  
  private static long gcd(long m, long n) {
    if(m < n) return gcd(n, m);
    if(n == 0) return m;
    return gcd(n, m % n);
}
}


Measured memory_bytes: 163392
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        char[] at = "atcoder".toCharArray();
        int n = sc.nextInt();
        Station[] st = new Station[n-1];
        int[] ans = new int[n];
        for(int i = 0; i < n-1; i++){
            st[i] = new Station(sc.nextInt(),sc.nextInt(),sc.nextInt());
        }
        for(int i = 0; i < n-1; i++){
            ans[i] = st[i].c+st[i].s;
            for(int j = i+1; j < n-1; j++){
                if(ans[i] <= st[j].s){
                    ans[i] = st[j].c + st[j].s;
                }else{
                    int tmp = ans[i] - st[j].s;
                    int pow = (int)Math.ceil((double)tmp/(double)st[j].f);
                    ans[i] = st[j].c + st[j].s + pow*st[j].f;
                }
            }
        }
        for(int a : ans){
            System.out.println(a);
        }
    }
}

class Station {
    int c,s,f;
    public Station(int c, int s, int f){
        this.c = c;
        this.s = s;
        this.f = f;
    }
}

Measured memory_bytes: 26356
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int n, a, x, D = 3000;
long long ans[6000];
int main(){
	scanf("%d%d", &n, &a);
	ans[D] = 1;
	rep(i,n){
		scanf("%d", &x);
		x -= a;
		if(x > 0) for(int i = 5600; i >= x; i--) ans[i] += ans[i-x];
		else rep(i,5600) ans[i] += ans[i-x];
	}
	printf("%lld\n", ans[D]-1);
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;

//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _KTy, typename _Ty> istream& operator >> (istream& istr, pair<_KTy, _Ty>& m) { cin >> m.first >> m.second; return istr; }
template <typename _Ty> istream& operator >> (istream& istr, vector<_Ty>& v) { for (size_t i = 0; i < v.size(); i++) cin >> v[i]; return istr; }
ll modpow(ll n, ll p, ll m) { ll result = 1; while (p > 0) { if (p & 1) result = (result * n) % m; p >>= 1; n = (n * n) % m; } return result; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
#define fake false


int f(int x) {
	int res = 0;
	while (x) {
		res += x % 10;
		x /= 10;
	}
	return res;
}

bool Harshad(int x) {
	return x % f(x) ? fake : true;
}

int main() {
	int N;
	cin >> N;
	cout << (Harshad(N) ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = (a), i##_end_ = (b); i <= i##_end_; ++i)
#define drep(i, a, b) for(int i = (a), i##_end_ = (b); i >= i##_end_; --i)
#define clar(a, b) memset((a), (b), sizeof(a))
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define Debug(s) debug("The massage in line %d, Function %s: %s\n", __LINE__, __FUNCTION__, s)
typedef long long LL;
typedef long double LD;
int read() {
    char ch = getchar();
    int x = 0, flag = 1;
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') flag *= -1;
    for(;isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    return x * flag;
}
void write(LL x) {
    if(x < 0) putchar('-'), x = -x;
    if(x >= 10) write(x / 10);
    putchar(x % 10 + 48);
}

const int Maxn = 22, Mod = 1e9 + 7;
int n, a[Maxn][Maxn]; 
LL dp[1 << Maxn];

void init() {
	n = read();
	rep (i, 1, n) 
		rep (j, 1, n) a[i][j] = read();
}

LL dfs(int stat) {
	if (dp[stat] != -1) return dp[stat];
	LL &res = dp[stat], cnt = __builtin_popcount(stat);
	res = 0;
	rep (i, 0, n - 1) 
		if ((stat & (1 << i)) != 0 && a[n - cnt + 1][i + 1] != 0) 
			(res += dfs(stat ^ (1 << i))) %= Mod;
	return res;	
}

void solve() {
	clar(dp, -1), dp[0] = 1;
	cout << dfs((1 << n) - 1) << endl;
}

int main() {
   // freopen("AtcoderDpO.in", "r", stdin);
    //freopen("AtcoderDpO.out", "w", stdout);

    init();
    solve();

#ifdef Qrsikno
    debug("\nRunning time: %.3lf(s)\n", clock() * 1.0 / CLOCKS_PER_SEC);
#endif
    return 0;
}



Measured memory_bytes: 33024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		StringBuilder output = new StringBuilder();
		Scanner scan = new Scanner(System.in);
		
		while(true) {
			int H = scan.nextInt();
			int W = scan.nextInt();
			
			if (H == 0 && W == 0)
				break;
			
			for (int i = 0; i < W; i++) {
				output.append("#");
			}
			output.append('\n');
			for (int i = 1; i < H-1; i++) {
				output.append("#");
				for (int j = 1; j < W-1; j++) {
					output.append(".");
				}
				output.append("#");
				output.append('\n');
			}
			for (int i = 0; i < W; i++) {
				output.append("#");
			}
			output.append('\n').append('\n');
		}
		
		System.out.print(output);
	}

}

Measured memory_bytes: 20692
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = getInt(sc);
		int k = getInt(sc);
		int[] h = getIntArray(sc);
		if (n <= k) {
			System.out.println(0);
		} else {
			Arrays.sort(h);
			long count = 0;
			for (int i = 0; i < n - k; i++) {
				count += h[i];
			}
			System.out.println(count);
		}
	}

	private static boolean isEqual(Integer[] perm, int[] target) {
		for (int i = 0; i < perm.length; i++) {

			if (perm[i].intValue() != target[i]) {

				return false;
			}
		}
		return true;
	}

	/**
	 * *汎用メソッド<br>
	 * 入力した配列に対する順列を取得
	 *
	 * @param numArray
	 * @return
	 */
	private static List<Integer[]> getPermutation(int[] numArray) {
		List<Integer[]> permutation = new ArrayList<>();
		Integer[] ans = new Integer[numArray.length];
		boolean[] used = new boolean[numArray.length];

		return buildPermutaion(permutation, numArray, ans, used, 0);
	}

	/**
	 * *汎用メソッド(内部)<br>
	 * 入力した配列に対する順列を作成
	 *
	 * @param list
	 * @param numArray
	 * @param ans
	 * @param used
	 * @param depth
	 * @return
	 */
	private static List<Integer[]> buildPermutaion(List<Integer[]> list, int[] numArray, Integer[] ans, boolean[] used,
			int depth) {

		// 全部使い切った時=>できた順列を返す
		if (depth == numArray.length) {
			list.add(ans.clone());
			return list;
		}
		// 使い切っていない場合

		for (int i = 0; i < numArray.length; i++) {
			if (used[i]) {
				continue;
			}
			ans[depth] = numArray[i];
			used[i] = true;
			list = buildPermutaion(list, numArray, ans, used, depth + 1);

			used[i] = false;
		}

		return list;
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

}


Measured memory_bytes: 77340
def sh(num):
    for n in num:
        out(n)
def out(n):
    number = []
        # print(n[0])
        # print(n[1])
    for i in range(n[1]):
        number.append("#")
    for i in range(n[0]):
        print(''.join(number))
    print('')

num = []
while True:
    n = list(map(int, input().split()))
    if n[0] == 0 and n[1] == 0:
        break
    else:
        num.append(n)
sh(num)

Measured memory_bytes: 7704
#include <iostream>
#include <cmath>
#include <map>
#include <utility>
#include <list>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

#define LL long long

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

    int total = 0;

    if (a + b >= c) {
        total = b + c;
    } else {
        total = b + (a + b + 1);
    }

    cout << total << endl;    

    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int n,m;
    cin >> n >> m;
    int a[n][m],b[m],ans[n] = {};
    for(int i = 0;i < n;i++)
    {
        for(int j = 0;j < m;j++)
        {
            cin >> a[i][j];
        }
    }
    for(int i = 0;i < m;i++)
    {
        cin >> b[i];
    }
    for(int i = 0;i < n;i++)
    {
        for(int j = 0;j < m;j++)
        {
            ans[i] += a[i][j] * b[j];
        }
    }
    for(int i = 0;i < n;i++)
    {
        cout << ans[i] << "\n";
    }

    return 0;
}


Measured memory_bytes: 3156
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define INF 1000000007
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2)*pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int jo(int n) {
	int ans = 1;
	rep(i, n) {
		ans *= 2;
	}
	return ans;
}

signed main() {
	int n, a, b;
	cin >> n >> a >> b;
	n -= a;
	cout << n % b << endl;
}


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

using namespace std; 

int isPrime(int n){
	if(n==1) return 0;
	if(n<=3) return n;
	if(n%2==0) return 0;
	for(int i=3;i<=sqrt(n);i+=2)
	if(n%i==0) return 0;
	return n;
}

int main() { 	
	int x;
	cin>>x;
	int p;
	while(true){
		p=isPrime(x);
		if(p){
			cout<<x<<endl;
			break;
		}else{
			x++;
		}
	}
	
		return 0; }


Measured memory_bytes: 256
N = int(input())

# 包除原理を用いる

#「あるi, jがあって A_i=0 かつ A_j=9」とは、排反事象を取ると：
# 全体(10^N通り) - 「全てのiで A_i != 0 または A_i != 9」
#「全てのiで A_i != 0 または A_i != 9」はベン図で考えると：
#「全てのiで A_i = {0,1,2,3,4,5,6,7,8}」+「全てのiで A_i = {1,2,3,4,5,6,7,8,9}」-「全てのiで A_i = {1,2,3,4,5,6,7,8}」
# 以上から、求める値は：10^N - 2*9^N + 8^N
ans = 10**N - 2*9**N + 8**N
ans %= 10**9+7
 
print(ans)

Measured memory_bytes: 10960
# include <bits/stdc++.h>
# define mem(i) memset(i , 0 , sizeof i)
# define int long long
using namespace std;
const int N = 3002 , mod = 1e9 + 7;
int d[N][N] , res; 
main(){
      int n; string s;
      cin >> n >> s;
      d[1][1] = 1;
      for(int i = 2; i <= n; i ++){
            vector < int > pref(i + 2);
            pref[0] = 0; 
            for(int j = 1; j < i; j ++)
                  pref[j] = (pref[j - 1] + d[i - 1][j]) % mod;
            for(int j = 1; j <= i; j ++){
                  int l , r; 
                  if(s[i - 2] == '<'){
                        l = 1;
                        r = j - 1; 
                  }
                  else{
                        l = j;
                        r = i - 1;
                  }
                  if(l <= r)d[i][j] = (pref[r] - pref[l - 1] + mod) % mod;
            }
      }
      for(int i = 1; i <= n; i ++) res += d[n][i];
      cout << res % mod << "\n";
}

Measured memory_bytes: 68992
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    scanf("%d",&n);
    vector<int> v;
    
    for(int i=0;i<n;i++){
        int z;
        scanf("%d",&z);
        z--;
        v.push_back(z);
    }
    int now=0,c=0;
    for(;;)
    {
        if(now == 1)
        {
            printf("%d\n",c);
            break;
        }
        if(c>=n)
        {
            printf("-1\n");
            break;
        }
        c++;
        now = v[now];
    }
}

Measured memory_bytes: 892
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
#define inf 1e18
using namespace std;

const int maxn = 310;
const ll Mod = 1e9+7;

struct node
{
	ll x,y;
	node(){}
	node(const ll _x,const ll _y){x=_x;y=_y;}
}a[maxn][maxn]; int kn[maxn];
ll f[maxn];

void G(int k) // gernerate k+1
{
	for(int i=1;i<=kn[k];i++)
	{
		ll y=a[k][i].x,x=a[k][i].y;
		for(int j=1;;j++)
		{
			y+=x; if(y>f[k+3]) break;
			a[k+1][++kn[k+1]]=node(x,y);
		}
	}
}
ll solve(ll n,ll m,int k)
{
	ll re=0;
	if(k<=0)
	{
		for(int i=1;i<=n;i++)
		{
			ll k1=n/i,k2=m/i;
			(re+=k1*2ll%Mod-1+k2-k1)%=Mod;
		}
	}
	else
	{
		for(int i=1;i<=kn[k];i++)
		{
			ll y=a[k][i].x,x=a[k][i].y;
			// x px+y
			if(x>n) continue;
			ll k1=(n-y)/x,k2=(m-y)/x;
			(re+=k1*2ll%Mod+k2-k1)%=Mod;
		}
	}
	return re;
}

int main()
{
	f[0]=f[1]=1ll; for(int i=2;f[i-2]<=inf;i++) f[i]=f[i-1]+f[i-2];
	a[1][1]=node(1,2); a[1][2]=node(1,3); kn[1]=2;
	for(int i=2;f[i]<=inf;i++) 
		G(i-1);
	
	int t; scanf("%d",&t);
	while(t--)
	{
		ll x,y; scanf("%lld%lld",&x,&y); if(x>y) swap(x,y);
		int k;	for(k=1;f[k+1]<=y&&f[k]<=x;k++);k--;
		k--; if(k<0) k=0;
		ll ans=solve(x,y,k);
		printf("%d %lld\n",k+1,(ans+Mod)%Mod);
	}
	
	return 0;
}


Measured memory_bytes: 4352
import math

N,D = list(map(int, input().split(" ")))
X = []

while True:
    try:
        X.append(list(map(int, input().split(" "))))
    except:
        break

def calc_dist(Y,Z):
	ans = 0
	for y, z in zip(Y,Z):
		ans += (y-z)**2
	return math.sqrt(ans)

ans = 0
for i in range(N-1):
	for j in range(i+1, N):
		dist = calc_dist(X[i], X[j])
		if dist.is_integer():
			ans += 1

print(ans)

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

#define _GLIBCXX_DEBUG

//vector<int> A(M), B(M);
//vector<vector<char>> answer(N, vector<char>(N, '-'));

int main() {
  string s;
  int ans = 0;
  
  cin >> s;
  
  if(s[0] == 'R'){
    ans++;
    if(s[1] == 'R'){
      ans++;
      if(s[2] == 'R') ans++;
    }
  }
  
  else{
    if(s[1] == 'R'){
      ans++;
      if(s[2] == 'R') ans++;
    }
    else{
      if(s[2] == 'R') ans++;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

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

using namespace std;
using ll = long long;

int n, m;
vector<vector<int>> to, ot;
vector<bool> seen_par;
vector<int> ans;



void dfs(int v, int par) {
    for(auto i : ot[v])if(seen_par[i])return; //次の世代の子供ではない

    ans[v] = par;
    seen_par[v] = false;

    for(auto i : to[v]) {
        dfs(i, v);
    }

    seen_par[v] = true;
}

int main()
{
    cin >> n >> m;
    to.resize(n), ot.resize(n), seen_par.resize(n, true), ans.resize(n);

    for(int i = 0; i < m + n - 1; i++) {
        int a, b; cin >> a >> b; a--, b--;
        to[a].push_back(b);
        ot[b].push_back(a);
    }


    for(int i = 0; i < n; i++) {
        dfs(i, -1);
    }

    for(int i = 0; i < n; i++) {
        cout << ans[i] + 1 << endl;
    }

}

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

using namespace std;

int main(void)
{
	string s, t;
	cin >> s >> t;
	char tmp;
	for (int i = 0; i < s.length(); i++) {
		if (s == t) {
			cout << "Yes" << endl;
			return 0;
		}
		else {
			tmp = s[s.length() - 1];
			for (int i = s.length() - 2; i >= 0; i--) {
				s[i + 1] = s[i];
			}
			s[0] = tmp;
		}
	}
	cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 256
/**
 * @author torith
 * @date 2018-10-24
 */

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int a[100000] = {};
    for (int i = 0; i < N; ++i) {
        int t;
        cin >> t;
        a[t]++;
    }

    int ans = 0;
    for (int i = 0; i < 100000 - 2; ++i) {
        ans = max(ans,a[i]+a[i+1]+a[i+2]);
    }
    cout << ans << "\n";

    return 0;
}



Measured memory_bytes: 640
k,n = map(int,input().split())
a = list(map(int,input().split()))

max1 = 0
for i in range(1,n):
    max1 = max((a[i]-a[i-1]),max1)
max1 = max(max1,(a[0]+(k-a[n-1])))
print(k - max1)


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

inline int gi()
{
    char c = getchar();
    while(c < '0' || c > '9') c = getchar();
    int sum = 0;
    while('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
    return sum;
}

typedef long long ll;
const int maxn = 55, maxm = 105, mod = 1e9 + 7;

int n, m, col, fac[maxm << 1], ifac[maxm << 1];

struct edge
{
    int to, next;
} e[maxm * 2];
int h[maxn], tot;

inline void add(int u, int v)
{
    e[++tot] = (edge) {v, h[u]}, h[u] = tot;
    e[++tot] = (edge) {u, h[v]}; h[v] = tot;
}

int dfn[maxn], low[maxn], Time, top, bccno[maxn], cnt, siz_p[maxn], siz_e[maxn];
pair<int, int> stk[maxm];
vector<int> vec[maxn];

void dfs(int u, int fa)
{
    dfn[u] = low[u] = ++Time;
    for (int i = h[u], v; v = e[i].to, i; i = e[i].next)
        if (v != fa) {
            if (!dfn[v]) {
                stk[++top] = make_pair(u, v);
                dfs(v, u);
                low[u] = min(low[u], low[v]);
                if (dfn[u] <= low[v]) {
                    ++cnt;
                    while (1) {
                        int x = stk[top].first, y = stk[top].second;
                        ++siz_e[cnt];
                        if (bccno[x] != cnt) bccno[x] = cnt, ++siz_p[cnt], vec[cnt].push_back(x);
                        if (bccno[y] != cnt) bccno[y] = cnt, ++siz_p[cnt], vec[cnt].push_back(y);
                        --top;
                        if (x == u && y == v) break;
                    }
                }
            } else if (dfn[v] < dfn[u]) stk[++top] = make_pair(u, v), low[u] = min(low[u], dfn[v]);
        }
}

inline int fpow(int x, int k)
{
    int res = 1;
    while (k) {
        if (k & 1) res = (ll)res * x % mod;
        x = (ll)x * x % mod; k >>= 1;
    }
    return res;
}

inline int C(int n, int m)
{
    return (ll)fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}

int main()
{
    n = gi(); m = gi(); col = gi();
    
    for (int i = 1; i <= m; ++i) add(gi(), gi());

    for (int i = 1; i <= n; ++i)
        if (!dfn[i]) dfs(i, 0);

    fac[0] = ifac[0] = ifac[1] = 1;
    for (int i = 1; i <= m + col; ++i) fac[i] = (ll)fac[i - 1] * i % mod;
    for (int i = 2; i <= m + col; ++i) ifac[i] = (ll)(mod - mod / i) * ifac[mod % i] % mod;
    for (int i = 2; i <= m + col; ++i) ifac[i] = (ll)ifac[i - 1] * ifac[i] % mod;
    
    int ans1 = 1, ans2 = 1, ans3 = 1;
    for (int i = 1; i <= cnt; ++i)
        if (siz_e[i] == 1) ans1 = (ll)ans1 * col % mod;
        else if (siz_e[i] == siz_p[i]) {
            int sum = 0;
            for (int j = 1; j <= siz_e[i]; ++j) {
                sum += fpow(col, __gcd(j, siz_p[i]));
                if (sum >= mod) sum -= mod;
            }
            ans2 = (ll)ans2 * sum % mod * fpow(siz_e[i], mod - 2) % mod;
        } else ans3 = (ll)ans3 * C(siz_e[i] + col - 1, col - 1) % mod;

    printf("%lld\n", (ll)ans1 * ans2 % mod * ans3 % mod);
    //for(int i = 1; i <= m + col; i++) printf("%d %d\n", fac[i], ifac[i]);
    return 0;
}

Measured memory_bytes: 3656
#include <stdio.h>
#include <inttypes.h>

int64_t a(int64_t t) {
	if (t == 1) return 1;
	else return a(t / 2) * 2 + 1;
}

int main(void) {
	int64_t H;
	if (scanf("%" SCNd64, &H) != 1) return 1;
	printf("%" PRId64 "\n", a(H));
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &&x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define INSEG(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void PSUM(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(false);
        cout << setprecision(15) << fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

int N;
vector<int> a;
int dp[3000][3000][2];
int rec(int l, int r, int p) {
    if (l == r) {
        if (p == 0) return 0;
        else return a[l];
    }

    auto &DP = dp[l][r][p];
    if (DP != -1) return DP;

    int ret;
    int y1 = rec(l + 1, r, p ^ 1);
    int y2 = rec(l, r - 1, p ^ 1);
    if (p == 0) {
        // taro
        ret = min(y1, y2);
    } else {
        // jiro
        ret = max(y1 + a[l], y2 + a[r]);
    }
    return DP = ret;
}
signed main() {
    REP(i, 3000) REP(j, 3000) REP(k, 2) dp[i][j][k] = -1;
    cin >> N;
    a.resize(N);
    cin >> a;
    int S = accumulate(ALL(a), 0LL);

    cout << (S - rec(0, N - 1, 0) * 2) << endl;
    return (0^_^0);
}



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

using namespace std;

int main() {
    int A, B;
    cin >> A >> B;

    for (int i = 0; i <= 200000; ++i) {
        if (i * 8 / 100 == A and i * 10 / 100 == B) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

     

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

int main() {
	ll N, X, M;
	cin >> N >> X >> M;

	vector<ll> A(M,-1); // 回数
	vector<ll> B(M,-1); // Cumm
	ll c = 0;
	int f = 0;
	for(ll i = 1; i <= N; i++){
		c = c + X;
		if(A[X] == -1 || f == 1){ // まだ来てない
			A[X] = i;
			B[X] = c;
		}else{
			ll j = A[X]; // 周期 = i - j
			ll d = c - B[X];
			ll r = (N - i) / (i - j); // 周回数
			c += r * d;
			i = i + r * (i - j); // 周期回数
			f = 1;
		}
		X = (X * X) % M;
	}

	cout << c << endl;
	return(0);
}


Measured memory_bytes: 4752
from enum import Enum
from queue import Queue

import numpy as np

import collections
import bisect
import sys
import math

from scipy.sparse.csgraph import floyd_warshall
N,K,Q = map(int,input().split())
score = [K] * N

for i in range(Q):
    win = int(input())
    score[win-1] += 1

for i in range(N):
    if score[i]-Q > 0:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 17396
#include <iostream>
#include <queue>
#include <utility>

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

using namespace std;

const int INF = 1e9;

int main(){
  int H, W;
  cin >> H >> W;
  
  char G[H][W];
  rep(i,H) rep(j,W) cin >> G[i][j];
  
  int D[H][W];
  rep(k,H) fill(D[k], D[k]+W, INF);
  
  pair<int,int> s = make_pair(0,0);
  D[s.first][s.second] = 0;
  pair<int,int> g = make_pair(H-1,W-1);
  
  queue<pair<int,int> > que;
  que.push(s);
  
  int dy[] = {1,-1,0,0};
  int dx[] = {0,0,1,-1};
  
  bool ok = false;
  
  while(!que.empty()){
    pair<int,int> p = que.front();
    que.pop();
    
    if(p == g){
      ok = true;
      break;
    }
    
    rep(i,4){
      int y = p.first + dy[i];
      int x = p.second + dx[i];
      
      if(y < 0 || H <= y || x < 0 || W <= x || G[y][x] == '#') continue;
      if(D[y][x] != INF) continue;
      que.push(make_pair(y,x));
      D[y][x] = D[p.first][p.second] + 1;
    }
  }
  
  if(ok){
    int ans = 0;
    rep(l,H){
      rep(m,W){
        if(G[l][m] == '.') ans++;
      }
    }
    ans = ans - (D[g.first][g.second] + 1);
    cout << ans;
  }
  else{
    cout << "-1";
  }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int n,w,i,j,ans;
    cin>>n>>w;
    int wt[n],val[n];
    for(i=0;i<n;i++)
        cin>>wt[i]>>val[i];
    long long int dp[n+1][w+1];
    for(i=0;i<=n;i++){
        for(j=0;j<=w;j++){
            if(i==0||j==0)
                dp[i][j] = 0;
            else if(j>=wt[i-1]){
                dp[i][j] = max(dp[i-1][j], val[i-1] + dp[i-1][j-wt[i-1]]);
            }
            else
                dp[i][j] = dp[i-1][j];
        }
    }
    cout<<dp[n][w];
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2> 
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main(){
	int n;
	while(cin >>n){
		if(n==0) break;
		VI a(n);
		rep(i,n) cin >>a[i];
		double sm = accumulate(all(a), 0.0);
		double av = 1.0 * sm / n, ans =0;
		rep(i, n) ans += (av - a[i]) * (av - a[i]);
		printf("%.10f\n", sqrt(ans / n));
	}
	return 0;
}




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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

class UnionFindTree {
 private:
  int nodeSize;
  vector<int> parent;
  vector<int> rank;
  vector<int> treeSize;

 public:
  UnionFindTree(int ns) {
    nodeSize = ns;
    parent = vector<int>(nodeSize);
    rank = vector<int>(nodeSize, 0);
    treeSize = vector<int>(nodeSize, 1);

    for (int i = 0; i < nodeSize; i++) {
      parent[i] = i;
    }
  }

  int find(int x) {
    if (parent[x] == x) {
      return x;
    } else {
      return parent[x] = find(parent[x]);
    }
  }

  bool unite(int x, int y) {
    x = find(x);
    y = find(y);

    if (x == y) {
      return false;
    }

    if (rank[x] < rank[y]) {
      parent[x] = y;
      treeSize[y] += treeSize[x];
    } else {
      parent[y] = x;
      treeSize[x] += treeSize[y];
      if (rank[x] == rank[y]) {
        rank[x]++;
      }
    }

    return true;
  }

  bool same(int x, int y) { return find(x) == find(y); }

  int getSize(int x) { return treeSize[find(x)]; }
};

int main() {
  int n, m, k;
  cin >> n >> m >> k;

  UnionFindTree uf(n);
  vector<int> fri(n, 0), nofri(n, 0);

  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    uf.unite(a, b);
    fri[a]++;
    fri[b]++;
  }
  rep(i, k) {
    int c, d;
    cin >> c >> d;
    c--;
    d--;
    if (uf.same(c, d)) {
      nofri[c]++;
      nofri[d]++;
    }
  }

  rep(i, n) { cout << uf.getSize(i) - 1 - fri[i] - nofri[i] << ' '; }

  cout << endl;
}


Measured memory_bytes: 2816
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
    int n;
    cin >> n;
    vector<long int>f(n);
    int i;
    string s;
    s = "YES";
    for (i = 0; i < n; i++)
    {
        cin >> f.at(i);
    }
    sort(f.begin(), f.end());
    for (i = 0; i < n - 1; i++)
    {
        if (f.at(i) == f.at(i + 1))
        {
            s = "NO";
            break;
        }
    }
    cout << s << endl;
    
}

Measured memory_bytes: 4708