akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;
int main() {
    int n;
    cin >> n;
    vector<int> count(100001, 0);
    for(int i = 0; i < n; i++) {
        int a;
        cin >> a;
        count[a]++;
    }
    int s = 100001, t = 100001;
    for(int i = 0; i < 100001; i++) {
        if (count[i] >= 2) {
            s = i;
            break;
        }
    }
    if (s == 100001) {
        cout << n << endl;
        return 0;
    }
    for(int i = 100001; i >= 0; i--) {
        if (count[i] >= 2) {
            t = i;
            break;
        }
    }
    
    while(s < t) {
        if (count[s] >= 2) count[s]--;
        if (count[t] >= 2) count[t]--;
        while (count[s] <= 1) s++;
        while (count[t] <= 1) t--;
    }
    if (s == t) {
        count[s] = count[s] % 2;
    }
    int ans = 0;
    for(int i = 0; i < 100001; i++) {
        if (count[i] == 1){
            ans++;
        }
    }
    cout << ans << endl;
    
    return 0;
}

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

a_sum_last, b_sum_last, c_sum_last = 0, 0, 0
for _ in range(N):
    a_today, b_today, c_today = map(int, input().split())
    a_tomorrow = a_today + max(b_sum_last, c_sum_last)
    b_tomorrow = b_today + max(a_sum_last, c_sum_last)
    c_tomorrow = c_today + max(a_sum_last, b_sum_last)
    
    # Update
    a_sum_last = a_tomorrow
    b_sum_last = b_tomorrow
    c_sum_last = c_tomorrow

print(max(a_sum_last, b_sum_last, c_sum_last))


Measured memory_bytes: 3060
x,y = map(int,input().split())
gr_a = [1,3,5,7,8,10,12]
gr_b = [4,6,9,11]
gr_c = [2]

if x in gr_a and y in gr_a:
  print("Yes")
elif x in gr_b and y in gr_b:
  print("Yes")
else:
  print("No")

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

using namespace std;
typedef long long ll;

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

  char a[100][100];

  for (int i = 0; i < 50; i++) {
    for (int j = 0; j < 100; j++) {
      a[i][j] = '#';
    }
  }
  for (int i = 50; i < 100; i++) {
    for (int j = 0; j < 100; j++) {
      a[i][j] = '.';
    }
  }

  for (int i = 1; i < 50; i+=2) {
    bool flag = false;
    for (int j = 1; j < 100; j+=2) {
      if (A == 0) {
        flag = true;
        break;
      }
      a[i][j] = '.';
      A--;
    }
    if (flag) {
      break;
    }
  }
  for (int i = 51; i < 100; i+=2) {
    bool flag = false;
    for (int j = 1; j < 100; j+=2) {
      if (B == 0) {
        flag = true;
        break;
      }
      a[i][j] = '#';
      B--;
    }
    if (flag) {
      break;
    }
  }
  cout << 100 << " " << 100 << endl;
  for (int i = 0; i < 100; i++) {
    for (int j = 0; j < 100; j++) {
      cout << a[i][j];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
A.sort()

C = {}
for a in A:
  if a in C:
    C[a] += 1
  else:
    C[a] = 1
#print(C)
CK = [k for k in C.keys()]
#print(CK)
i = 0
flag = 0
while(i < len(CK)):
  if flag == 0:
    if C[CK[i]] >= 3:
      C[CK[i]] = 2 - (C[CK[i]] % 2)
    elif C[CK[i]] == 2:
      C[CK[i]] -= 1
      flag = 1
      i += 1
    else:
      i += 1
  else:
    if C[CK[i]] >= 2:
      C[CK[i]] -= 1
      flag = 0
    else:
      i += 1
ans = -flag
for val in C.values():
  ans += val
print(ans)


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

using namespace std;

typedef long long ll;
#define pb push_back

vector<ll> gr[100005];
ll dp[100005];

ll solve(ll node) {
	if (dp[node] != -1)
		return dp[node];

	bool leaf = true;
	ll ans = 0;
	for (ll child : gr[node]) {
		leaf = false;
		ans = max(ans, solve(child));
	}

	return dp[node] = (leaf) ? (0) : (1 + ans);
}

void fast() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

#ifndef tmr
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

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

	memset(dp, -1, sizeof dp);

	for (int i = 0; i < m; i++) {
		ll s, f;
		cin >> s >> f;
		gr[s].pb(f);
	}

	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		ans = max(ans, solve(i));
	}

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

Measured memory_bytes: 11860
#include <stdio.h>

int main(){
	
	char ch;
	int sum[1000] = {0};
	while((ch = getchar())!=EOF){
		sum[ch]++;
	}
	for(int i=97;i<=122;i++)
		printf("%c : %d\n", i, sum[i]+sum[i-32]);//注意要同时计算进大写和小写 
	

	return 0;
}


Measured memory_bytes: 2076
def main():
    a,b,c = input().split()
    mx = 0
    for i,first in enumerate([a,b,c]): #最初に一桁の数値を決める
        #print(first)
        second,third = [s for j,s in enumerate([a,b,c]) if j != i]
        if second < third:
            second,third = third,second
        if int(first) + int(second+third) > mx:
            mx = int(first) + int(second + third)
    print(mx)

main()


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

int main(){

  int N, flag=0;
  long x;
  cin >> N >> x;

  vector<long> vec(N);
  for (int i=0; i<N; i++){
    cin >> vec.at(i);
  }

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

  for (int i=0; i<N; i++){
    x -= vec.at(i);
    if (x<0){
      ++flag;
    }
  }

  if(flag>0){
    cout << N-flag << endl;
  }
  else if (x==0){
    cout << N << endl;
  }
  else {
    cout << N-1 << endl;
  }
}

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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,x,t;
    cin >> n >> x >> t;
    int ans = t *( (n+x-1)/x);
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////

ll n,m;
struct Chair{
    ll l,r;
    ll num;
    bool operator<(const Chair &op)const{return r<op.r;}
};
bool coml(Chair a,Chair b){
    return a.l>b.l;
}
int main(){
    cin>>n>>m;
    Chair c[n];
    rep(i,0,n-1){
        cin>>c[i].l>>c[i].r;
        c[i].num=i;
    }
    bool used[n];memset(used,false,sizeof(used));
    sort(c,c+n,coml);
    priority_queue<Chair>q;
    ll pos=0;
    for(ll time=m;time>=0;time--){
        while(pos<=n-1&&c[pos].l==time){
            q.push(c[pos]);
            pos++;
        }
        if(time==0)break;
        if(q.empty())continue;
        Chair t=q.top();q.pop();
        used[t.num]=true;
    }
    //rep(i,0,n-1)cout<<used[i]<<" ";cout<<endl;
    vector<ll>v;
    while(!q.empty()){
        auto x=q.top();q.pop();
        v.pb(x.r);
    }
    sort(v.begin(),v.end());
    ll ans=0;rep(i,0,n-1)if(used[i])ans++;
    ll vs=v.size();
    pos=0;
    vector<ll>pool;
    while(pos<=vs-1&&v[pos]<=ans){
        pool.pb(v[pos]);
        pos++;
    }
    for(ll time=ans+1;time<=m;time++){
        while(pos<=vs-1&&v[pos]==time){
            pool.pb(v[pos]);
            pos++;
        }
        if(pool.empty())continue;
        ans++;
        pool.pop_back();
    }
    cout<<n-ans<<endl;
    
    return 0;
}


Measured memory_bytes: 17260
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    vector<int> a(3);

    int k;
    cin >> a[0] >> a[1] >> a[2] >> k;
    vector<int>::iterator max = max_element(a.begin(), a.end());
    size_t index = distance(a.begin(), max);

    for (int i = 0; i < k; i++)
    {
        a[index] = a[index] * 2;
    }
    int sum = 0;
    for (int i = 0; i < 3; i++)
    {
        sum += a[i];
    }

    cout << sum << endl;
    return 0;
}


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

int n,m;
bool graph[50][50];
bool visited[50];
int a[50],b[50];

void dfs(int v){
  visited[v] = true;
  for(int v2=0;v2<n;v2++){
    if(graph[v][v2] == false) continue;
    if(visited[v2] == true) continue;
    dfs(v2);
  }
}

int main(){
  cin >> n >> m;
  for(int i=0;i<m;i++){
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }

  int ans = 0;

  for(int i=0;i<m;i++){
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;

    for(int j=0;j<n;j++) visited[j] = false;

    dfs(0);

    bool bridge = false;
    for(int j=0;j<n;j++){
      if(visited[j]==false) bridge = true;
    }
    if(bridge) ans++;

    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T
{
    std::io::Read::bytes(std::io::stdin())
                    .map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>()
                    .parse().ok().unwrap()
}

fn main() {
    let n: usize = read();
    let mut prime_numbers: Vec<i32> = vec![2];
    let mut ans: Vec<i32> = vec![];

    for i in (1..(55_555-1)/2).map(|x| x*2+1) { 
        let mut flag = true;
        for j in prime_numbers.iter() {
            if i % j == 0 {
                flag = false;
                break;
            }
        }
        if flag {
            prime_numbers.push(i);
            if i % 5 == 1 {
                ans.push(i);
                if ans.len() == n {break;}
            }
        }
    }
    
    print!("{}", ans[0]);
    for n in ans.iter().skip(1) {
        print!(" {}", n);
    }

}


Measured memory_bytes: 4352
#include <cstdio>

using namespace std;
int a,b,k;
int main(){
    scanf("%d%d%d",&k,&a,&b);
    for(int i=a;i<=b;i++)
        if(i%k==0){printf("OK");return 0;}
    printf("NG");
    return 0;
}

Measured memory_bytes: 1736
import sys
n, *CSF = list(map(int, sys.stdin.read().split()))
C = CSF[::3]
S = CSF[1::3]
F = CSF[2::3]


def solve(x):
    cur = 0
    for i in range(x, n - 1):
        y = cur % F[i]
        if S[i] > cur:
            cur = S[i] + C[i]
        elif y == 0:
            cur += C[i]
        else:
            cur += (F[i] - y) + C[i]
    return cur


for i in range(n - 1):
    print(solve(i))
print(0)


Measured memory_bytes: 68168
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define max 100005
using ll =long long;
using namespace std;

int main(){
    double pi=acos(-1);
    int r;
    cin>>r;
    cout<<2*pi*r<<endl;
    return 0;
}



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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

const int INF = 1'000'000'000;

int dhh[] = {1, 0, -1, 0};
int dww[] = {0, 1, 0, -1};
int dhh2[] = {2, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, -1, -1, -1, -1, -2, -2, -2, -2, -2};
int dww2[] = {2, 1, 0, -1, -2, 2, 1, -1, -2, 2, -2, 2, 1, -1, -2, 2, 1, 0, -1, -2};

int main() {
  int h, w;
  int ch, cw;
  cin >> h >> w;
  cin >> ch >> cw;
  ch--;
  cw--;
  int dh, dw;
  cin >> dh >> dw;
  dh--;
  dw--;
  vector<vector<char>> s(h, vector<char>(w));
  rep(i, h) {
    rep(j, w) {
      cin >> s.at(i).at(j);
    }
  }
  vector<vector<int>> d(h, vector<int>(w, INF));
  queue<P> que;
  queue<P> que2;
  que.push(P(ch, cw));
  d.at(ch).at(cw) = 0;
  while (!que.empty() || !que2.empty()) {
    P p;
    if (!que.empty()) {
      p = que.front();
      que.pop();
    } else {
      p = que2.front();
      que2.pop();
    }
    if (p.first == dh && p.second == dw) {
      continue;
    }
    rep(i, 4) {
      int ddh = dhh[i];
      int ddw = dww[i];
      if (ddh == 0 && ddw == 0) {
        continue;
      }
      int nh = p.first + ddh;
      int nw = p.second + ddw;
      if (nh < 0 || nh >= h) {
        continue;
      }
      if (nw < 0 || nw >= w) {
        continue;
      }
      if (s.at(nh).at(nw) != '.') {
        continue;
      }
      int cur = d.at(p.first).at(p.second);
      if (d.at(nh).at(nw) > cur) {
        que.push(P(nh, nw));
        d.at(nh).at(nw) = cur;
      }
    }
    rep(i, 20) {
      int ddh = dhh2[i];
      int ddw = dww2[i];
      if (ddh == 0 && ddw == 0) {
        continue;
      }
      int nh = p.first + ddh;
      int nw = p.second + ddw;
      if (nh < 0 || nh >= h) {
        continue;
      }
      if (nw < 0 || nw >= w) {
        continue;
      }
      if (s.at(nh).at(nw) != '.') {
        continue;
      }
      int cur = d.at(p.first).at(p.second);
      if (d.at(nh).at(nw) > cur + 1) {
        que2.push(P(nh, nw));
        d.at(nh).at(nw) = cur + 1;
      }
    }
  }

  int res = d.at(dh).at(dw);
  cout << (res == INF ? -1 : res) << endl;
  return 0;
}


Measured memory_bytes: 8492
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N;
    cin >> N;
    int A[N];
    rep(i, N) cin >> A[i];
    sort(A, A+N);
    cout << A[N-1]-A[0] << endl;
}

Measured memory_bytes: 256
N,W = map(int, input().split())
w = [0]*N
v = [0]*N
for i in range(N):
    w[i],v[i] = map(int,input().split())
dp = [[0] * (W + 1) for _ in range(N + 1)]
ans = int(0)
dp[0][0] = 0

for i in range(N):
    for j in range(W+1):
        if w[i]<=j:
            dp[i+1][j] = max(dp[i+1][j], dp[i][j-w[i]] + v[i])
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])

ans = dp[N][W]

print(ans)

Measured memory_bytes: 120684
#include "cstdio"
#include "algorithm"
#include "stack"
using namespace std;
stack<char>s1;
stack<char>s2;
char s[10000];
int main(){
    int n; scanf("%d",&n);
    scanf("%s",s+1);
    int ans=0;
    for(int i=n;i>=1;i--){
        if(s[i]==')')
            s1.push(')'),s2.push(')');
        else{
            if(!s1.empty())
                s1.pop(),s2.push('(');
            else s2.push('('),ans++;
        }
        
    }
    while(!s1.empty())
        s2.push('('),s1.pop();
    while(!s2.empty())
        printf("%c",s2.top()),s2.pop();
    while(ans--)
        putchar(')');
    puts("");
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    int house[4][3][10] = {};
    
    int n;
    scanf("%d",&n);
    
    int i;
    for(i=0;i<n;i++){
        int b,r,f,v;
        scanf("%d %d %d %d",&b,&r,&f,&v);
        house[b-1][r-1][f-1] += v;
    }
    
    int j,k;
    for(i=0;i<4;i++){
        for(j=0;j<3;j++){
            for(k=0;k<10;k++){
                printf(" %d",house[i][j][k]);
            }
            printf("\n");
        }
        if(i!=3){
            printf("####################\n");
        }
        
    }
    
    return 0;
}

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    N=I()
    L=[]
    R=[]

    
    for i in range(N):
        a,b=MI()
        L.append(a)
        R.append(b)
    L.sort()
    R.sort()
        
    #中央値の最小値は，Lの中央値．中央値の最大値はRの中央値
    #間は全部埋められそう?
        
    if N%2==0:
        Lm=(L[N//2]+L[N//2-1])
        Rm=(R[N//2]+R[N//2-1])
    else:
        Lm=L[N//2]
        Rm=R[N//2]
    ans=Rm-Lm+1
    print(ans)
        
        
        
        
        
    
            

main()


Measured memory_bytes: 92904
#include<bits/stdc++.h>
//#include<tr1/unordered_map>
//#pragma GCC optimize ("Ofast")
#define ll long long
#define pll pair<long long,long long>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define forn(i, n) for(int i=0; i<int(n); i++)
#define Forn(i, n) for(int i=1; i<=int(n); i++)

using namespace std;

int n;
string s;
int ans;

int main()
{
    cin.tie(0); ios_base::sync_with_stdio(false);
    cin >> n >> s;
    char now = s[0];
    int ans = 1;
    for(int i=1; i<s.size(); i++)
    {
        if(s[i]!=now) ans++;
        now = s[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <iostream>

#define MAX 100000

using namespace std;

int collisionSearch(int *array,int key,int num){

  int i;

  for(i = 0;i < num;i++){
    if(array[i] == key){
      return -1;
    }
  }

  return 0;
}

void countByBinary(int origin[],int cmp[],int size1,int size2){

  int i;
  int mid;
  int cnt = 0;
  int head = 0;
  int tail = size1;

  for(i = 0;i < size2;i++){
    head = 0;
    tail = size1;
    while(head < tail){
      mid = (head+tail)/2;
      if(origin[mid] == cmp[i]){
	//cout << "Finded:" << cmp[i] << endl;
	cnt++;
	break;
      }
      else if(origin[mid] < cmp[i]){
	head = mid+1;
      }
      else if(origin[mid] > cmp[i]){
	tail = mid;
      }
    }
  }

  cout << cnt << endl;
}

int main(){

  int i;
  int n;
  int q;
  int S[MAX];
  int T[MAX];
  int temp;

  cin >> n;

  // origin array
  for(i = 0;i < n;i++){
    cin >> S[i];
  }

  cin >> q;

  i = 0;
  // cmp array
  while(i != q){

    cin >> temp;

    if(collisionSearch(T,temp,i) != 0){
      q--;
      continue;
    }

    T[i] = temp;
    i++;
  }

  countByBinary(S,T,n,q);

  return 0;
}

Measured memory_bytes: 1752
#include <iostream>

using namespace std;

int main()
{
   int a, b;
   cin >> a >> b;
   
   if (a == b)
       cout << "a == b" << endl; 
   else if (a > b)
       cout << "a > b" << endl;
   else
       cout << "a < b" << endl;
   
   return 0;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    long long int n,w,i,j,x=0;
    cin>>n>>w;
    long long int b[n],c[n];
    for(i=0;i<n;i++)
    {
        cin>>b[i]>>c[i];
        x=x+c[i];
    }
    long long int a[x+1];
    for(i=0;i<=x;i++)
    {
       a[i]=w+1;
    }
    a[0]=0;
    for(i=0;i<n;i++)
    {
        for(j=x;j>=1;j--)
        {
            if(j-c[i]>=0)
            {
                a[j]=min(a[j],/*a[j]-*/a[j-c[i]]+b[i]);
            }
        }
        /*for(j=0;j<=x;j++)
        {
            cout<<a[j]<<" ";
        }cout<<endl;*/
    }
    a[0]=0;
    for(i=x;i>=0;i--)
    {
        if(a[i]<=w)
        {
            cout<<i;
            break;
        }
    }
    return 0;
}




Measured memory_bytes: 1024
def r(a, b, c, d, e, f):
    return a * (d-f) + c * (f-b) + e * (b-d) > 0

while True:
    try: line = list(map(float, input().split()))
    except: break
    
    x1, y1, x2, y2, x3, y3, xp, yp = line
    abc = r(x1, y1, x2, y2, x3, y3)
    pab = r(xp, yp, x1, y1, x2, y2)
    pbc = r(xp, yp, x2, y2, x3, y3)
    pca = r(xp, yp, x3, y3, x1, y1)

    print('YES' if abc == pab == pbc == pca else 'NO')


Measured memory_bytes: 5584
N ,D = map(int,input().split())

X = [list(map(int, input().split())) for i in range(N)]
count=0

sum=0

for i in range(N):
  for j in range(1,N-i):
    for a,b in zip(X[i],X[i+j]):
      sum += (a-b)**2
    if sum**(0.5)==int(sum**(0.5)):
      count=count+1
    sum=0    

print(count)


Measured memory_bytes: 3060
import java.util.Scanner;
public class Main{
    public static Scanner scan  = new Scanner(System.in);
    public static void main(String[]args){
        String [] abc = new String[3];
        abc[0]=next();
        abc[1]=next();
        abc[2]=next();
        int[] i_abc={0,0,0};
        int now=0;
        char tmp;

        while/*(
            i_abc[0]<=abc[0].length()&&
            i_abc[1]<=abc[1].length()&&
            i_abc[2]<=abc[2].length()
            )*/
            (true)
        {

            if(i_abc[now]<abc[now].length()) tmp=abc[now].charAt(i_abc[now]);
            else break;
            i_abc[now]+=1;
            switch (tmp){
                case 'a':
                    now=0;
                    break;
                case 'b':
                    now=1;
                    break;
                case 'c':
                    now=2;
                    break;
            }
        }
        /*
        if(i_abc[0]>=abc[0].length()) print('A');
        else if(i_abc[1]>=abc[1].length()) print('B');
        else if(i_abc[2]>=abc[2].length()) print('C');
        */
        switch(now){
            case 0:
                print("A");
                break;
            case 1:
                print("B");
                break;
            case 2:
                print("C");
                break;
        }
    }



    public static int nextInt(){
        return Integer.parseInt(scan.next());
    }
    public static long nextLong(){
        return Long.parseLong(scan.next());
    }
    public static String next(){
        return scan.next();
    }
    public static double nextDouble(){
        return Double.parseDouble(scan.next());
    }
    public static float nextFloat(){
        return Float.parseFloat(scan.next());
    }

    //Yes or No
    public static void yesNo(boolean flag){
        if(flag) System.out.println("Yes");
        else System.out.println("No");
    }
    public static void print(Object a){
        System.out.println(a);
    }
}


Measured memory_bytes: 23124
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;
using ll = long long;

int n;

int ha() {
    if (n<4) return 3;
    char c;
    for (auto i=0;i<n;i++) {
        cin>>c;
        if (c=='Y') return 4;
    }
    return 3;
}


int main(int argc, const char * argv[]) {
    cin>>n;
    
    cout<<(ha()==3?"Three":"Four");
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>

#define INF 1000000
using namespace std;

int check(long long vertex, long long *island,
		long long *x1, long long *y1, long long *x2, long long *y2,
		long long N, long long M, long long island_num){
	if(island[vertex]==-1){
		island[vertex]=island_num;
	
	for(long long i=lower_bound(x1,x1+M,vertex)-x1; i<upper_bound(x1,x1+M,vertex)-x1; i++){
		if(island[y1[i]]==-1){
			check(y1[i],island,x1,y1,x2,y2,N,M,island_num);
		}
	}
	for(long long i=lower_bound(x2,x2+M,vertex)-x2; i<upper_bound(x2,x2+M,vertex)-x2; i++){
		if(island[y2[i]]==-1){
			check(y2[i],island,x1,y1,x2,y2,N,M,island_num);
		}
	}
	
	}
	return 0;
}


int main() {
	long long N,M;
	cin >> N >> M;
	
	if(M==0){
		if(N==1){
			cout << 0 << endl;
		}else if(N==2){
			long long a1,a2;
			cin >> a1 >> a2;
			cout << a1 + a2 << endl;
		}else{
			cout << "Impossible"<<endl;
		}
		return 0;
	}
	
	long long a[N];
	for(long long i=0; i<N; i++){
		cin >> a[i];
	}
	
	long long x[M],y[M];
	for(long long i=0; i<M; i++){
		cin >> x[i] >> y[i];
	}
	
	pair<long long, long long> edgex[M],edgey[M];	//x and i
	for(long long i=0; i<M; i++){
		edgex[i].first=x[i];
		edgex[i].second=y[i];
		
		edgey[i].first=y[i];
		edgey[i].second=x[i];
	}
	
	sort(edgex,edgex+M);
	sort(edgey,edgey+M);
	
	long long x1[M], y1[M];
	long long x2[M], y2[M];
	for(int i=0; i<M; i++){
		x1[i]=edgex[i].first;
		y1[i]=edgex[i].second;
		x2[i]=edgey[i].first;
		y2[i]=edgey[i].second;
	}
	
	
	long long island[N];
	for(long long i=0; i<N; i++){
		island[i]=-1;
	}
	
	for(long long cnt=0; cnt<N; cnt++){
		if(island[cnt]==-1){
			check(cnt,island,x1,y1,x2,y2,N,M,cnt);
		}
	}
	
//	for(int i=0; i<N; i++){
//		cout << island[i] << " ";
//	}
//	cout << endl;
			
	pair<long long, long long> ki[N];
	for(int i=0; i<N; i++){
		ki[i].first=island[i];
		ki[i].second=a[i];
	}
	
	sort(ki,ki+N);
	
	long long hayashi=1;
	long long temp=ki[0].first;
	for(int i=0; i<N; i++){
		if(ki[i].first!=temp){
			hayashi++;
			temp=ki[i].first;
		}
	}
	
//	cout << hayashi << endl;
	
	
	if(hayashi*2>N+2){
		cout << "Impossible"<<endl;
		return 0;
	}
	
	if(hayashi==1){
		cout << 0 << endl;
		return 0;
	}
	
	if(hayashi==2){
		long long ans=0;
		ans+=ki[0].second;
		for(long long i=1; i<N; i++){
			if(ki[i].first!=ki[i-1].first){
				ans+=ki[i].second;
				break;
			}
		}
		cout << ans << endl;
		return 0;
	}
	
	long long answer=0;
	long long left[N-hayashi]={};
	long long cnt=0;
	
	temp=-1;
	for(long long i=0; i<N; i++){
		if(ki[i].first!=temp){
			answer+=ki[i].second;
			temp=ki[i].first;
		}else{
			left[cnt]=ki[i].second;
			cnt++;
		}
	}
	sort(left,left+N-hayashi);
	for(long long i=0; i<hayashi-2; i++){
		answer+=left[i];
	}
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 11904
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();
		int powN = (int)(Math.pow(2, N) + 0.5);
		int M = scan.nextInt();
		int X = scan.nextInt();
		int f = 0;
		int total[] = new int[M+1];
		int C[] = new int[N+1];
		int A[][] = new int[N+1][M+1];
		int ans = 0;
		for(int i = 1; i < N+1; i++) {
			C[i] = scan.nextInt();
			for(int j = 1; j < M+1; j++) {
				A[i][j] = scan.nextInt();
			}
		}


		for (int i = 1; i < N+1; i++) {
			for (int j = 1; j < M+1; j++) {
				total[j] += A[i][j];
			}
			total[0] += C[i];
		}

		for (int j = 1; j < M+1; j++) {
			if (total[j] >= X) {
				continue;
			}
			f++;
		}

		if (f > 0) {
			ans = -1;
		} else {
			ans = total[0];

			for (int i = 1; i < powN; i++) {
				for (int j = 0; j < M+1; j++) {
					total[j] = 0;
				}
				f = 0;
				int powk = 1;
				for (int k = 1; k < N+1; k++) {
					if ((i & powk) == powk) {
						total[0] += C[k];
						for (int j = 1; j < M+1; j++) {
							total[j] += A[k][j];
						}
					}
					powk *= 2;
				}

				for (int j = 1; j < M+1; j++) {
					if (total[j] >= X) {
						continue;
					}
					f++;
				}

				if (f == 0 && ans > total[0]) {
					ans = total[0];
				}

			}
		}

		System.out.println(ans);

	}
}

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

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

int main() {
    int n;
    cin >> n;
    vector<int> a(n),b(n),cnt(n+1,0);
    for (int i = 0;i < n;++i) cin >> a[i];
    for (int i = 0;i < n;++i) cin >> b[i];
    reverse(b.begin(),b.end());
    for (int i = 0;i < n;++i) cnt[a[i]]++;
    for (int i = 0;i < n;++i) cnt[b[i]]++;
    for (int i = 0;i < n+1;++i) if (cnt[i] > n) {
        cout << "No" << newl;
        return 0;
    }
    cout << "Yes" << newl;
    int j = 0,k = n-1;
    for (int i = 0;i < n;++i) if (a[i] == b[i]) {
        if (a[j] != a[i] && b[j] != a[i]) {
            swap(b[i],b[j]);
            j++;
        } else {
            swap(b[i],b[k]);
            k--;
        }
    }
    for (int i = 0;i < n;++i) cout << b[i] << " \n"[i == n-1];
}

Measured memory_bytes: 5584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const  ll INF = 1e9;
const  ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i,n,init) for(ll i=init;i<(n);i++)
#define repd(i,n,init) for(ll i=(n);i>=init;i--)
#define repm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define repb(bit,n,init) for(ll bit=init;bit<(1<<n);++bit)

vector<ll> fact, invfact;
ll modpower(ll x, ll n, ll mod){
    ll res = 1;
    while(n){
        if(n&1)res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
ll inv(ll n){
    return modpower(n,MOD-2,MOD);
}
void COMinit(ll k){ //空っぽの配列を二つ
   k++;
   fact.resize(k, 0);
   invfact.resize(k, 0);
   fact[0] = 1;
   repi(i, k, 1)
   {
       fact[i] = fact[i - 1] * i % MOD;
   }
   invfact[k - 1] = inv(fact[k - 1]);
   repd(i, k - 2, 0)
   {
       invfact[i] = invfact[i + 1] * (i + 1) % MOD;
   }
   return;
}
ll nCk(vector<ll> &fact,vector<ll> &invfact,ll n, ll k){ //この関数を使う前にCOMinit
   if (k < 0 || n < k)
       return 0LL;
   return fact[n] * invfact[k] % MOD * invfact[n - k] % MOD;
}
ll com(ll n, ll k)
{
    ll iv = 1;
    ll fa = 1;
    repi(i, k, 0)
    {
        fa *= (n - i);
        fa %= MOD;
    }
    repi(i, k + 1, 1)
    {
        iv *= inv(i);
        iv %= MOD;
    }
    return fa * iv % MOD;
}

//---------main function----------

int main()
{
    int n,m;
    cin >> n >> m;
    cout << com(n,2) + com(m,2) << endl;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define Rrep(i,n) for(int i=((int)n-1); i>=0; i--)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e15
#define MOD 1000000007

typedef vector<int> vint;
typedef long long ll;



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

        ll n;
        ll x,m;

        //ll size=1;
        

        cin>>n>>x>>m;

        ll sum=x;

        vector<ll> a;
        a.push_back(x);

        ll index;
        
        rep(i,m){
                ll tmp=(a[i]*a[i])%m;
                auto itr=find(a.begin(),a.end(),tmp);
                index=distance(a.begin(),itr);
                if(tmp==0){
                        cout<<sum<<endl;
                        return 0;
                }
                if(itr!=a.end()){
                        break;
                }
                else{a.push_back(tmp);sum+=tmp;}
        }

        ll roop = (n-index)/(a.size()-index)-1;
        ll r = (n-index)%(a.size()-index);

        ll roopsum=0;
        for(int i = index; i < a.size(); i++){
                roopsum += a[i];
        }

        sum += roopsum*roop;
        rep(i,r){
                sum += a[index+i];
        }

        cout<<sum<<endl;
        return 0;
}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
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 (a>b) { a=b; return 1; } return 0; }

ll beki(int a, int n)
{
    if(n == 0){
        return 1;
    }
    int ans = beki(a, n / 2);
    ans = ans * ans;
    if(n % 2 == 1){
        ans = ans * a;
    }
    return ans;
}

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

    int N,M; cin >> N >> M;

    cout << (1900*M + 100*(N-M)) * beki(2,M) << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

MOD = 10**9+7
N, Q = map(int, readline().split())
A = [int(readline()) for _ in range(N)]

dp = [[0]*N for _ in range(N)]

tinv = pow(2, MOD-2, MOD)
for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            dp[i][j] = 1

for q in range(Q):
    x, y = map(int, readline().split())
    x -= 1
    y -= 1
    dxy = dp[x][y]
    dyx = dp[y][x]
    ix = [None]*N
    iy = [None]*N
    xi = [None]*N
    yi = [None]*N
    for i in range(N):
        r1 = (dp[i][x] + dp[i][y])*tinv%MOD
        ix[i] = r1
        iy[i] = r1
        r2 = (dp[x][i] + dp[y][i])*tinv%MOD
        xi[i] = r2
        yi[i] = r2
    for i in range(N):
        dp[x][i] = xi[i]
        dp[y][i] = yi[i]
        dp[i][x] = ix[i]
        dp[i][y] = iy[i]
    dp[x][y] = (dxy + dyx)*tinv%MOD
    dp[y][x] = dp[x][y]
    dp[x][x] = 0
    dp[y][y] = 0

res = 0
for i in range(N):
    for j in range(i+1, N):
        res = (res+dp[i][j])%MOD
print(res*pow(2, Q, MOD)%MOD)
    

Measured memory_bytes: 120796
use proconio::input;

fn main() {
    input! {
        n: usize,
        a: [u64; n+1],
    }
    let nodes: Vec<_> = a
        .iter()
        .rev()
        .scan(0, |cum, &x| {
            let val = *cum;
            *cum = *cum + x;
            Some(val)
        })
        .collect();
    let (mut stage, mut result) = (1, 1);
    for (&ai, &ni) in a.iter().zip(nodes.iter().rev()) {
        if ai > stage {
            println!("{}", -1);
            std::process::exit(0);
        }
        stage = ni.min((stage - ai) * 2);
        result += stage;
    }
    println!("{}", result);
}


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

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

  if (n == 2 || m == 2) {
    cout << 0 << endl;
  } else if (n == 1 && m == 1) {
    cout << 1 << endl;
  } else if (n == 1) {
    cout << m - 2 << endl;
  } else if (m == 1) {
    cout << n - 2 << endl;
  } else {
    cout << (n * m) - (m * 2) - (n - 2) * 2 << endl;
  }

  // vector<string> s(n);
  // for (int i = 0; i < n; i++) {
  //  string line = "";
  //  for (int j = 0; j < m; j++) {
  //    line += ".";
  //  }
  //  s[i] = line;
  //}

  // for (int i = 0; i < n; i++) {
  //  for (int j = 0; j < m; j++) {
  //    s[i][j] = (s[i][j] == '#' ? '.' : '#');
  //    if (i != 0) s[i - 1][j] = (s[i - 1][j] == '#' ? '.' : '#');
  //    if (i != n - 1) s[i + 1][j] = (s[i + 1][j] == '#' ? '.' : '#');
  //    if (j != 0) s[i][j - 1] = (s[i][j - 1] == '#' ? '.' : '#');
  //    if (j != m - 1) s[i][j + 1] = (s[i][j + 1] == '#' ? '.' : '#');
  //    if (i != 0 && j != 0)
  //      s[i - 1][j - 1] = (s[i - 1][j - 1] == '#' ? '.' : '#');
  //    if (i != 0 && j != m - 1)
  //      s[i - 1][j + 1] = (s[i - 1][j + 1] == '#' ? '.' : '#');
  //    if (i != n - 1 && j != 0)
  //      s[i + 1][j - 1] = (s[i + 1][j - 1] == '#' ? '.' : '#');
  //    if (i != n - 1 && j != m - 1)
  //      s[i + 1][j + 1] = (s[i + 1][j + 1] == '#' ? '.' : '#');
  //  }
  //}
  // for (int i = 0; i < n; i++) {
  //  cout << s[i] << endl;
  //}
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>
#include <map>
#include <queue>
#include <stack>

using namespace std;
int main(int argc, const char * argv[]) {
    
    int n;
    cin >> n;
    string s;
    cin >> s;
    int r=0, b=0;
    for (int i=0; i<n; i++){
        if(s[i]=='R') r++;
        else  b++;
    }

    cout << ((r>b) ? "Yes":"No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>
using namespace std;

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

#define rep(i,n) for(int i=0; i<n; i++)
#define repa(i,s,e) for(int i=s; i<=e; i++)
#define repd(i,s,e) for(int i=s; i>=e; i--)

template <typename T> T tmax(T t1, T t2) { return t1 > t2 ? t1 : t2; }

const int MAX_NS = 10;
const int MAX_NL = 20;
int ns, nl, s1, s2, d;
int S[MAX_NS][MAX_NS];
char L[MAX_NS][MAX_NS];

int dfs(int k, vi& v, int dist) {
	int maxval = dist;
	vi mv;
	int next = -1;

	rep(i,ns) {
		if(S[k][i] != 0 && L[k][i] != 1) {
			L[k][i] = L[i][k] = 1;
			int val = dfs(i, v, dist+S[k][i]);
			if(maxval < val) {
				maxval = val;
				mv = v;
				mv.push_back(i);
			}
			L[k][i] = L[i][k] = 0;
		}
	}

	v = mv;

	return maxval;
}

int main() {
	while(cin>>ns>>nl, nl | ns) {
		memset(&S[0][0], 0, sizeof(int) * MAX_NS * MAX_NS);
		memset(&L[0][0], 0, sizeof(char) * MAX_NS * MAX_NS);
		
		rep(i,nl) {
			cin>>s1>>s2>>d;
			s1--; s2--;
			S[s1][s2] = S[s2][s1] = d;
		}

		int next = -1;
		int maxval = 0;
		vi mv, v;
		rep(i,ns) {
			int val = dfs(i, v, 0);
			if(maxval < val) {
				maxval =  val;
				mv = v;
				mv.push_back(i);
			}
		}
		
		cout << maxval << endl;
		repd(i,mv.size()-1,0) {
			printf("%d", mv[i]+1);
			if(i!=0) printf(" ");
		}
		printf("\n");
	}
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign

string path;
vb used(8, false);
vvb graph(8, vb(8, false));
int n, m, ret = 0;

void mp();
int search();

signed main()
{
    cin >> n >> m;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        graph[a-1][b-1] = true;
        graph[b-1][a-1] = true;
    }
    used[0] = true;
    path.pb(0);
    mp();
    cout << ret << endl;

    return 0;
}

void mp()
{
    if (path.size() == n) {
        ret += search();
    } else {
        Rep(i, n) {
            if (!used[i]) {
                used[i] = true;
                path.pb(i);
                mp();
                used[i] = false;
                path.pop_back();
            }
        }
    }
}

int search()
{
    int state = path[0];
    Rep(i, n) {
        if (!graph[state][path[i]]) {
            return 0;
        } else {
            state = path[i];
        }
    }
    return 1;
}



Measured memory_bytes: 256
N = int(input())
T, A = map(int, input().split())
H = [int(i) for i in input().split()]

dif = 1000

for i in range(N):
    tmp = T - H[i] * 0.006
    if abs(A - tmp) < dif:
        dif = abs(A - tmp)
        ans = i + 1

print(ans)


Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
#define L 9
#define MAXN 10
long long H,W;
long long ans[MAXN+5];
long long N;
map<pair<int,int>,int> G;
int xl[10]={-1,-1,-1,0,0,1,1,1,0};
int yl[10]={-1,0,1,-1,1,-1,0,1,0};
void Init()
{
	ans[0]=(W-2)*(H-2);
}
int main()
{
	scanf("%d %d %lld",&H,&W,&N);
	Init();
	int x,y; 
	for(int i=1;i<=N;i++)
	{
		scanf("%d %d",&x,&y);
		for(int i=0;i<L;i++)
		{
			int a=x+xl[i],b=y+yl[i];
			if(a<=H&&a>=1&&b<=W&&b>=1)
			{
				int num=(++G[make_pair(a,b)]);
				if(a>=2&&a<=H-1&&b>=2&&b<=W-1)
				{
					ans[num]++;
					ans[num-1]--;
				}
			}
		}
	}
	for(int i=0;i<=9;i++)
	{
		printf("%lld\n",ans[i]);
	}
}

Measured memory_bytes: 42496
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""

def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

inf = 10 ** 18
mod = 10 ** 9 + 7

_INPUT = """\
4
141421356 17320508 22360679 244949
"""

def main(*, input=input):
    sr = lambda: input()
    ir = lambda: int(sr())
    lr = lambda: list(map(int, sr().split()))

    n = ir()
    a = lr()
    a1 = [0]
    for num in a:
        a1.append(a1[-1]+num)
    ans = 0
    for i,num in enumerate(a):
        tmp = (a1[n]-a1[i+1])%mod
        tmp = (tmp*num)%mod
        ans = (ans+tmp)%mod
    print(ans)

if __name__ == "__main__":
    import io, sys

    # sys.stdin = io.StringIO(_INPUT)

    main()

Measured memory_bytes: 112348
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    int n,m;
    cin >> n >> m;
    vector<bool> v(n+10,1);
    rep(i,m){
        int x;
        cin>>x;
        v[x]=0;
    }
    vector<ll> dp(n+10,0);
    dp[0]=1;
    rep(i,n){
        if(v[i] && dp[i]!=0){
            if(v[i+1]) dp[i+1] += dp[i];
            if(v[i+2]) dp[i+2] += dp[i];
            dp[i+1]%=mod;
            dp[i+1]%=mod;
        }
    }
    //rep(i,n) cout<<dp[i]<<" ";
    //cout<<endl;
    cout<<dp[n]<<endl;
    return 0;
}

Measured memory_bytes: 1024
/*
 * yaswanth phani kommineni
 */
#include <bits/stdc++.h>
using namespace std;
typedef      long long int 	ll;

void solve(){
	ll x,s,y=100,ye=0;
	cin >> x;
	while(y<x){
		s=(y/100);
		y+=s;
		ye++;
	}
	cout << ye << endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);	
	solve();
	return 0;
}


Measured memory_bytes: 3564
#include <iostream>
#include <set>
#define llint long long

using namespace std;

llint Q;
llint n;
set<llint> S;

llint get(llint x)
{
  llint keta = 0;
  for(llint t = x; t; t/=10) keta++;
  llint mul = 10, ret = 0;
  for(int i = 0; i < keta-1; i++){
    ret = max(ret, x/mul * (x%mul));
    mul *= 10;
  }
  return ret;
}

int main(void)
{
  cin >> Q;
  for(int i = 0; i < Q; i++){
    cin >> n;
    llint ans = 0;
    S.clear();
    S.insert(n);
    while(1){
      if(n < 10){
        cout << ans << endl;
        break;
      }
      n = get(n);
      ans++;
      if(S.count(n)){
        cout << -1 << endl;
        break;
      }
      S.insert(n);
    }
  }
  return 0;
}



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

int main() {
  int N; cin >> N;
  vector<int> x(N), y(N);
  for (int i = 0; i < N; i++) cin >> x.at(i) >> y.at(i);
  if (N == 1) { cout << 1 << endl; return 0; }
  int ans = 100;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i == j) continue;
      int p = x.at(i) - x.at(j);
      int q = y.at(i) - y.at(j);
      int cnt = 0;
      for (int s = 0; s < N; s++) {
        for (int t = 0; t < N; t++) {
          int a = x.at(s) - x.at(t);
          int b = y.at(s) - y.at(t);
          if (a == p && b == q) cnt++;
        }
      }
      ans = min(ans, N - cnt);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            var week = new string[]{"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
            var s = Console.ReadLine().Trim();

            foreach(var i in Enumerable.Range(0, 7)){
                if(week[i].Equals(s)){
                    Console.WriteLine(7 - i);
                    break;
                }
            }
        }
    }
}


Measured memory_bytes: 11220
K = int(input())
A, B = [int(x) for x in input().split(" ")]
this = A // K
tag = 0
for i in range(this*K, B+1, K):
    if(A<=i<=B):
        tag = 1
        break
if tag == 1:
    print("OK")
else:
    print("NG")


Measured memory_bytes: 61908
def getScore(d):
    return int(d[1]) * 3 + int(d[3])
    
isFirst = True

while 1:
    n = int(input())
    if n == 0:
        break
    if not isFirst:
        print()
    table = []
    for i in range(0,n):
        d = list(_ for _ in input().split())
        score = getScore(d)
        table.append((d[0],score))
    table.sort(key=lambda i:i[1],reverse=True)
    
    for n,s in table:
        print(str(n) + ',' + str(s))
    isFirst = False


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

int main() {
  ll N, K, S;
  cin >> N >> K >> S;
  ll num;
  if (S == 1000000000) num = 999999999;
  else num = 1000000000;
  vector<ll> ans(N, num);
  for (int i = 0; i < K; i++) ans[i] = S;
  for (int i = 0; i < N; i++) cout << ans[i] << " ";
  cout << endl;
}


Measured memory_bytes: 4008
n, l = (int(i) for i in input().split())  
ate_ix = -1
if l > 0:
  ate_ix = 1
elif abs(l) < n:
  ate_ix = -l+1
else:
  ate_ix = n

taste = 0
for i in range(1,n+1):
  if i == ate_ix:
    pass
  else:
    taste = taste+l+i-1
print(taste)

Measured memory_bytes: 3060
#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>

int main()
{
    int n;
    std::cin >> n;
    std::vector<int> w(n);
    for (int i = 0; i < n; i++) {
        std::cin >> w[i];
    }

    int ans = INT_MAX;
    for (int i = 1; i < n; i++) {
        int s1 = 0, s2 = 0;
        for (int j = 0; j < i; j++) {
            s1 += w[j];
        }
        for (int j = i; j < n; j++) {
            s2 += w[j];
        }
        ans = std::min(ans, abs(s1 - s2));
    }

    std::cout << ans << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

int main() {
  long double a;
  cin >> a;
  long double b;
  cin >> b;
  ll c = a*b;
  cout << c << endl;
  return 0;
}

Measured memory_bytes: 3732
ary = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
n = int(input())
print(ary[n-1])

Measured memory_bytes: 3060
package main

import (
	"fmt"
)

func main() {

	var N int
	fmt.Scanf("%d", &N)

	var A int
	var sum float64 = 0
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &A)
		sum += 1.0 / float64(A)
	}

	fmt.Println(1.0 / sum)
}


Measured memory_bytes: 1836