akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
   for (int i = 0; i < (b+2); i++)
   {
        cout<<"#";
   }
   cout<<endl;
   for (int i = 0; i < a; i++)
   {
       string str;
       cin>>str;
       cout<<"#"+str+"#"<<endl;
   }
      for (int i = 0; i < (b+2); i++)
   {
        cout<<"#";
   }
   
   

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
typedef pair<ll,ll> P;
signed main(){
    P a,b;
    ll n,m;
    cin>>n>>m;
    a.first=n,a.second=n*2;
    b.first=m,b.second=m*2;
    ll cnt1=0,cnt2=0;
    ll atk;
    
    while(1){
        atk=min(n,a.second);
        b.second-=atk;
        if(b.second<=0) break;
        cnt1++;
        
        
        atk=min(m,b.second/2+b.second%2);
        a.second-=atk;
        if(a.second<=0) break;
        cnt1++;
        
    }
    
    a.first=n,a.second=n*2;
    b.first=m,b.second=m*2;
    
    while(1){
        atk=min(n,a.second/2+a.second%2);
        b.second-=atk;
        if(b.second<=0) break;
        cnt2++;
        
        
        atk=min(m,b.second);
        a.second-=atk;
        if(a.second<=0) break;
        cnt2++;
        
    }
    ll ans=min(cnt1,cnt2);
    cout<<ans<<endl;
    return 0;
}




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

#define x first
#define y second
#define pb push_back
#define mp make_pair

#define all(a) (a).begin(), (a).end()

#define int long long

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, a, b;
    cin >> n >> a >> b;
    if (abs(a - b) % 2 == 0) {
        cout << (abs(a - b) / 2);
    } else {
        if (a > b) swap(a, b);
        cout << min(a + (b - a - 1) / 2, n - b + 1 + (b - a - 1) / 2);
    }
    return 0;
}


Measured memory_bytes: 256
INF = int(1e9 + 7)


def factorial(x):
    FCT = 1
    for i in range(2, x + 1):
        FCT = i * FCT % INF
    return FCT


def main():
    N, M = map(int, input().split())
    MIN_NM = factorial(min(N, M))
    if N == M:
        print(2 * MIN_NM ** 2 % INF)
    elif abs(N - M) <= 1:
        print(MIN_NM ** 2 * max(N, M) % INF)
    else:
        print(0)

    return


main()


Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)

def main():
    H = int(input().strip())
    W = int(input().strip())
    N = int(input().strip())
    ans = N // max(H, W)
    if N % max(H, W) > 0:
        ans += 1
    return ans

if __name__ == "__main__":
    print(main())

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

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

    for (int x=0; x<=n; x++) {
        for (int y=0; x+y<=n; y++) {
            int z = n - x - y;
            int total = 10000*x + 5000*y + 1000*z;
            if (total == Y && x + y == n - z) {
                cout << x << " " << y << " " << z << endl;
                return 0;
            }
        }
    }

    cout << "-1 -1 -1" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
   int a,b;
   cin>>a>>b;
   int h=b-a;
   int T=0,ans;
   rep(i,h){
       T+=i+1;
   }
   ans=T-b;
   cout<<ans<<endl;
}

Measured memory_bytes: 3532
S = input()
S_list = list(S)

cnt = 0
max_s = 0

for s in S_list:
    if (s == "A") or (s == "C") or (s == "G") or (s == "T"):
        cnt += 1
    else:
        if max_s < cnt:
            max_s = cnt
        cnt = 0
if max_s < cnt:
    max_s = cnt
print(max_s)


Measured memory_bytes: 3060
# https://atcoder.jp/contests/agc039/submissions/7877660
from collections import deque

INF = float('inf')


def bfs(n, es):
    parity = [-1] * n
    parity[0] = 0

    dq = deque()
    dq.append(0)
    while dq:
        v = dq.popleft()
        nxt_par = parity[v] ^ 1
        for u in es[v]:
            if parity[u] == -1:
                parity[u] = nxt_par
                dq.append(u)
            else:
                if parity[u] != nxt_par:
                    return False
                    # bipartite = False
    return True
    # bipartite = True


def warshall_floyd(n, g):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                g[i][j] = min(g[i][j], g[i][k] + g[k][j])
    return g


def solve():
    n = int(input())
    es = tuple(set() for _ in range(n))
    g = []
    for v in range(n):
        s = input()
        for u, is_adj in enumerate(map(int, s)):
            if is_adj:
                es[v].add(u)
                es[u].add(v)
        g.append(list(map(int, s)))
    for r, row in enumerate(g):
        for c, cell in enumerate(row):
            if cell == 0 and r != c:
                g[r][c] = INF
        # 隣接頂点間: 1
        # 同一頂点間: 0
        # その他: INF
    # print(es)
    # print(g)

    # 二部グラフ判定
    bipartite = bfs(n, es)
    if not bipartite:
        return -1

    # 最遠点対間距離を求める
    g = warshall_floyd(n, g)
    d = max(max(row) for row in g)
    return d + 1


if __name__ == '__main__':
    print(solve())


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

int main() {
    int K;
    cin >> K;
    ll ans = 0;
    for (int i = 1; i <= K; i++) {
        for (int j = 1; j <= K; j++) {
            for (int k = 1; k <= K; k++) {
                ans += gcd(gcd(i, j), k);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3592
// AOJ 1194 "バンパイア" (ICPC国内予選 2014 Problem C)
import java.util.Scanner;
import java.util.Arrays;

public class Main {
    public static double INF = 100.0;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        while (true) {
            int r = sc.nextInt();
            int n = sc.nextInt();
            if (r == 0) {
                break;
            }
            
            // field[y][x]: (x-20, y-1)にシルエット(境界も含む)があればtrue
            boolean[][] field = new boolean[41][81];
            Arrays.fill(field[0], true); // 地面に陰があると見なす
            
            for (int i = 0; i < n; i++) {
                int xl = sc.nextInt();
                int xr = sc.nextInt();
                int h  = sc.nextInt();
                
                for (int j = 1; j <= 2 * h; j++) {
                    Arrays.fill(field[j], (xl + 20) * 2, (xr + 20) * 2 + 1, true);
                }
            }
            //printField(field);
            
            double minTime = INF;
            for (int i = 0; i < field.length; i += 2) {
                for (int j = 0; j < field[i].length; j += 2) {
                    if (isBorder(field, j, i)) {
                        // シルエットの上下の境界ならば、円との交点を求める
                        double time = crossTime(j/2 - 20, i/2, r);
                        minTime = Math.min(minTime, time);
                    }
                }
            }
            System.out.println(minTime);
        }
    }
    
    public static boolean isBorder(boolean[][] field, int x, int y) {
        if (!field[y][x]) {
            return false;
        } else if (y == field.length - 1 || (x == 0 || x == field[y].length - 1) && !field[y+1][x]) {
            return true;
        } else if (!field[y+1][x]) {
            return true;
        } else {
            int num = 0;
            for (int i = 0; i <= 1; i++) {
                for (int j = -1; j <= 1; j++) {
                    if (x + j >= 0 && x + j < field[y+i].length && field[y+i][x+j]) {
                        num++;
                    }
                }
            }
            return num == 5 ? true : false;
        }
    }
    
    public static double crossTime(int x, int y, int r) {
        //System.out.println("x: " + x + ", y: " + y + ", r: " + r);
        int d = (int)Math.pow(-2 * (y + r), 2) - 4 * (x * x + y * y + 2 * y * r);
        if (d <= 0) {
            return INF;
        } else {
            double ans = (2 * (y + r) - Math.sqrt(d)) / 2;
            //System.out.println(d + " " + Math.sqrt(d) + " " + ans);
            return ans;
        }
    }
    
    public static void printField(boolean[][] field) {
        for (int i = field.length - 1; i >= 0; i -= 2) {
            for (int j = 0; j < field[i].length; j += 2) {
                if (field[i][j]) {
                    System.out.print("-");
                } else {
                    System.out.print(" ");
                }
            }
            System.out.println();
        }
    }
}

Measured memory_bytes: 29196
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdlib>
using namespace std;


int main()
{
	int a, b;
	cin >> a >> b;
	if (a >= 13)
		cout << b << endl;
	else if (a <= 5)
		cout << 0 << endl;
	else
		cout << b / 2 << endl;
	
}

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

int main(){
  int h,w;
  string s=".-|+x";
  cin>>w>>h>>s[4];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      int f=0;
      if(i==0||i==h-1)f++;
      if(j==0||j==w-1)f+=2;
      if(i==h/2&&j==w/2)f=4;
      cout<<s[f];
    }
    cout<<endl;
  }
  return 0;
}



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

using namespace std;

#define ll long long



int main(){
  ll K;
  ll q,c;
  cin >> K;

  cout << "50" << endl;
  vector <ll> a(50,49);
  q = K/50;
  c = K%50;

  for(ll i = 0;i<50;i++){a[i]+=q;};
  for(ll i =0;i<c;i++){
    for(ll j =0;j<50;j++){
      a[j]--;
    }
    a[i]+=51;
  }


  for(ll i = 0;i<50;i++){
    cout << a[i] << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
public class Main {

  private static void solve() {
    int n = ni();
    int[][] p = ntable(n, 2);
    
    int g = 0;
    for (int[] q : p) {
      g ^= grundy(q[0], q[1]);
    }
    System.out.println(g == 0 ? "Aoki" : "Takahashi");
  }

  
  static int grundy(int a, int k) {
    if (a < k) return 0;
    if (a % k == 0) return a / k;
    
    int diff = a / k + 1;
    return grundy(a - Math.max((a % k) / diff, 1) * diff, k);
    
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = System.getProperty("debug");
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 27476
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			int m = scan.nextInt();
			int max = m;
			for(int i = 0;i < n;i++){
				int in = scan.nextInt();
				int out = scan.nextInt();
				if(m < 0){
					continue;
				}
				m += in - out;
				if(max < m){
					max = m;
				}
			}
			System.out.println((m < 0)?0:max);
		}
	}
}

Measured memory_bytes: 39744
/****************
 *		*
 *ALDS_1_5_B	*
 *Merge Sort	*
 *		*
 *2019/08/20	* 
 *		*
 ****************/

#include<iostream>
#include<cstdio>

using namespace std;

#define MAX_ARRAY 500000
#define MAX_LIMIT 1000000001

int count_compare = 0;
int S[MAX_ARRAY] = {0};

void merge(int left,int mid,int right){
  int i,j,k;
  int n1 = mid - left;
  int n2 = right - mid;
  int Left[MAX_ARRAY];
  int Right[MAX_ARRAY];
  
  for(i=0;i<n1;i++) Left[i] = S[left + i];
  Left[n1] = MAX_LIMIT;
  for(j=0;j<n2;j++) Right[j] = S[mid + j];
  Right[n2] = MAX_LIMIT;

  i=0;
  j=0;

  for(k=left;k<right;k++){
    count_compare++;
    if(Left[i] <= Right[j]){
      S[k] = Left[i];
      i++;
    }
    else {
      S[k] = Right[j];
      j++;
    }
  }
}

void mergeSort(int left,int right){
  if((left + 1) < right){
    int mid = (left + right)/2;
    mergeSort(left,mid);
    mergeSort(mid,right);
    merge(left,mid,right);
  }

  return;
  
}

int main(void){

  int n=0;

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

  mergeSort(0,n);

  for(int i=0;i<n;i++) {
    if(i > 0) printf(" ");
    printf("%d",S[i]);
  }
  printf("\n");

  printf("%d\n",count_compare);
  
  return 0;
}



Measured memory_bytes: 7068
#include "bits/stdc++.h"
using namespace std;
 
typedef long long ll;
typedef long double f80;
 
// #define int long long
#define pii pair<int,int>
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ef emplace_front
#ifndef LOCAL
#define endl '\n'
#endif

const int mod = 1e9 + 7;

ll pwr(ll a, ll b) {
    ll ans = 1;
    while(b) {
        if(b & 1) ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}

bool dp[46][100005];

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    #ifdef LOCAL
        freopen("inp.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    string s;
    cin >> s;
    int n = sz(s);
    s = '0' + s;
    int ans = n;
    fr(i, 1, n) {
        if(s[i] == '1') {
            int j = i;
            while(j <= n && s[j] == '1') j++;
            j--;
            ans = min(ans, max({i - 1, n - j, min(j, n - i + 1)}));
            i = j;
        }
    }
    cout << ans;
    return 0;
}

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

int main() {
  int N,a;
  cin >> N;
  vector<int> num(9,0);
  for (int i=0; i<N; i++) {
    cin >> a;
    num[min(a/400,8)]++;
  }
  int ans = 0;
  for (int i=0; i<8; i++) {
    if (num[i] != 0) {
      ans++;
    }
  }
  cout << max(ans,1) << ' ' << ans + num[8] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ff first
#define ss second
#define endl '\n'
#define MAX INT_MAX
#define MIN INT_MIN
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
#define pb push_back
#define sz(a) (int)((a).size())
#define all(a) a.begin(),a.end()
#define loopf(i,a,b) for(int i = a;i < b;i++)
#define loopb(i,a,b) for(int i = a;i >= b;i--)
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;


int32_t main()
{
    fast

   int test=1;
   //cin>>test;


  //while(test--)
  //{
  
    int n;
    cin>>n;
    int sum=0;
    for(int i=1;i<=n;i++)
    {
      for(int j=1;j<=n;j++)
      {
        for(int k=1;k<=n;k++)
        {
          sum+=__gcd(i,__gcd(j,k));
        }
      }
    }

    cout<<sum;

  //while loop ending
 // }
  

return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main(){
  string l="qazwsxedcrfvtgb";
  string r="yhnujmikolp";
  while(1){
    string s;
    cin >> s;
    if(s[0]=='#') break;
    int str = 0;
    for(int i=0; i<(int)l.size(); i++){
      if(s[0]==l[i]) str=1;
    }
    int ans = 0;
    for(int i=0; i<(int)s.size(); i++){
      if(str==0){
        for(int j=0; j<(int)l.size(); j++){
          if(s[i]==l[j]){
            str=1;
            ans++;
          }
        }
      }
      else{
        for(int j=0; j<(int)r.size(); j++){
          if(s[i]==r[j]){
            str=0;
            ans++;
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}



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

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define DEBUG(x) cout << #x"=" << x << endl

#define INFTY INT_MAX/3

#define MAX_N 100

int main(void){

	int n, l;
	string s[MAX_N];

	cin >> n >> l;
	REP(i, n) cin >> s[i];

	sort(s, s + n);

	string ans = "";

	REP(i, n) ans += s[i];

	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int ninzu,num;
  scanf("%d",&ninzu);
  int junban[ninzu];
  for(int i=1; i<=ninzu;i++){
    scanf("%d",&num);
    junban[num-1]=i;
  }
  for(int i = 0 ;i<ninzu-1;i++){
    printf("%d ",junban[i]);
  }
  printf("%d",junban[ninzu-1]);
  return 0;
}

Measured memory_bytes: 1280
S = 0
P = 0
N,M = map(int,input().split())
if N == 0:
    S = 0
else:
    for i in range(1,N):
        S += i
if M == 0:
    P = 0
else:
    for i in range(1,M):
        P += i
print(S+P)

Measured memory_bytes: 3060
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)


void solve(long long N, long long M, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C){
    map<ll, ll, greater<ll> > mp;
    rep(i, N){
        mp[A[i]]++;
    }
    rep(i, M){
        mp[C[i]]+= B[i];
    }
    ll res = 0;
    for(auto it: mp){
        ll num = min(N, it.second);
        res += num * it.first;
        N -= num;
        if(N == 0)
            break;
    }
    cout << res << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    std::vector<long long> B(M);
    std::vector<long long> C(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&B[i]);
        scanf("%lld",&C[i]);
    }
    solve(N, M, std::move(A), std::move(B), std::move(C));
    return 0;
}


Measured memory_bytes: 15104
S=input()
if S=="SUN":
  print(7)
elif S=="MON":
  print(6)
elif S=="TUE":
  print(5)
elif S=="WED":
  print(4)
elif S=="THU":
  print(3)
elif S=="FRI":
  print(2)
elif S=="SAT":
  print(1)

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

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

signed main(){
	int n;
	cin>>n;
	int m = n-1;
	int freq[n];
	f(i,n) freq[i]=0;
	int dummy;
	f(i,m){
		cin>>dummy;
		freq[dummy-1]++;
	}
	f(i,n) cout<<freq[i]<<endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

int main(){

  ll n,k;cin>>n>>k;
  ll h[n+10];rep(i,0,n)cin>>h[i];

  vector<ll>cost(n,1e9);
  cost[0]=0;
  rep(i,0,n){
    rep(j,i+1,min(i+k+1,n)){
      cost[j]=min(cost[j],cost[i]+abs(h[i]-h[j]));
    }
  }

  out(cost[n-1]);

  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

struct pa{
	int a,b,c;
	pa(){}
	pa(int a,int b,int c):a(a),b(b),c(c){}
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int a,b,c;
	cin>>a>>b>>c;
	map<tuple<int,int,int>,int> mp;
	int ct = 0;
	bool inf = false;
	while(!(a&1)&&!(b&1)&&!(c&1)){
		if(mp[tie(a,b,c)] > 0){
			inf = true;break;
		}else{
			mp[tie(a,b,c)]++;
			ct++;
			int ta = a,tb = b;
			a = b/2 + c/2;
			b = ta/2 + c/2;
			c = ta /2 + tb /2;
		}
	}
	if(inf)cout << -1 << endl;
	else cout << ct << endl;
  return 0;
}


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

int main()
{

    while (1)
    {
        int n;
        cin >> n;
        if (n == 0)
            return 0;
        set<int> v[100];
        rep(i, n)
        {
            int m;
            cin >> m;
            rep(j, m)
            {
                int p;
                cin >> p;
                v[i].insert(p);
            }
        }
        int k;
        cin >> k;
        vector<int> l(k);
        rep(i, k) cin >> l[i];
        int cnt = 0, num;
        rep(i, n)
        {
            bool b = true;
            for (auto li : l)
            {
                if (!v[i].count(li))
                {
                    b = false;
                    break;
                }
            }
            if (b)
            {
                cnt++;
                num = i + 1;
            }
        }
        cout << (cnt == 1 ? num : -1) << "\n";
    }
}



Measured memory_bytes: 3456
from sys import stdin, setrecursionlimit
#input = stdin.buffer.readline
setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi, radians, sin, cos

MOD = 10 ** 9 + 7
INF = 10 ** 18

N = int(input())
#S = input()
#N, M = map(int, input().split())
#A = list(map(int, input().split()))
#A = [int(input()) for _ in range(N)]
#ABC = [list(map(int, input().split())) for _ in range(N)]

N %= 1000
if N == 0:
    print(0)
else:
    print(1000 - N)

Measured memory_bytes: 65184
#include <stdio.h>
int main()
{
int n,i,j;
int ans;
char era[1000000];
while(scanf("%d",&n) != EOF){
for(i=0; i<=n;i++)
era[i]=1;
ans=0;
for(i=2;i<=n;i++){
if(era[i] == 1){
ans++;
for(j=i; j<=n;j+=i)
era[j]=0;
}
}
printf("%d\n",ans);
}
return 0;
}

Measured memory_bytes: 2000
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	private void dfs(int c, long sum) {
		ans[c] += z[c] + sum;

		sum += z[c];

		for (int child : tree.get(c)) {
			dfs(child, sum);
		}
	}

	private void dfs2(int c, long sum) {
		Deque<List<Long>> q = new ArrayDeque<List<Long>>();
		
		q.add(Arrays.asList((long)c,sum));
		
		while(!q.isEmpty()) {
			List<Long> e = q.poll();
			int cc = (int)(long)e.get(0);
			long ss = e.get(1);
			
			ans[cc] = z[cc] + ss;
			
			ss += z[cc];
			
			for (int child : tree.get(cc)) {
				q.add(Arrays.asList((long)child, ss));
			}
		}
		
	}
	
	List<List<Integer>> tree;
	long[] ans;
	long[] z;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int Q = sc.nextInt();

		tree = new ArrayList<>();

		for (int i = 0; i <= N; i++) {
			tree.add(new ArrayList<>());
		}

		for (int i = 1; i <= N - 1; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();

			tree.get(a).add(b);
		}

		z = new long[N + 1];

		for (int i = 1; i <= Q; i++) {
			int p = sc.nextInt();
			int x = sc.nextInt();

			z[p] += x;
		}

		sc.close();

		ans = new long[N + 1];

		dfs2(1, 0);

		out.println(join(" ", ans));

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private String join(String delimiter, long[] a) {
		StringBuilder sb = new StringBuilder();

		for (int i = 1; i < a.length; i++) {
			sb.append(a[i]);
			sb.append(delimiter);
		}
		return sb.substring(0, Math.max(sb.length() - delimiter.length(), 0));
	}
}


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

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#pragma GCC optimize("Ofast")
//1.0 * clock() / CLOCKS_PER_SEC

#define fi first
#define se second
#define ll long long
#define dl double long

using namespace std;

const int NN = 1e6 + 7;
const int N = 2e5 + 7;
const int M = 20;
const ll mod = 998244353;
const ll inf = 1e18 + 7;
const dl rf = 1e-14;

void solve1()
{
    ll x;
    cin >> x;
    cout.precision(6);
    dl ans = x * 1.0 / 3;
    cout << fixed << ans * ans * ans;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0); srand(time(0));
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}


Measured memory_bytes: 256
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

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

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    IN(ll, K);
    set<ll> s;
    REP(i, K)
    {
        IN(ll, d);
        REP(j, d)
        {
            IN(ll, a);
            s.insert(a);
        }
    }
    ll ans = N - s.size();
    OUT(ans);
}

Measured memory_bytes: 3608
#include <iostream>

int main()
{
	int i, j;
	std::cin >> i >> j;
	int max = i + j;
	if (max < i * j)
	{
		max = i * j;
	}
	if (max < i - j)
	{
		max = i - j;
	}
	std::cout << max;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <stdio.h>
#include <string>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 998244353;
ll n, a[310], dp[90010], sum, ext, ans, dp2[90010];


ll pow(ll x, ll y)
{
	if (y == 0) return 1;
	if (y % 2)
	{
		return pow(x, y - 1) * x % mod;
	}
	else
	{
		ll yyy = pow(x, y / 2);
		return yyy * yyy % mod;
	}
}

ll div(ll x)
{
	return pow(x, mod - 2);
}



int main(void)
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	dp[0] = 1, dp2[0] = 1;
	for (int i = 0; i < n; i++)
	{
		for (int j = sum / 2; j >= 0; j--)
		{
			if (j >= a[i])
			{
				(dp[j] += dp[j - a[i]] * 2) %= mod;
				(dp2[j] += dp2[j - a[i]]) %= mod;
			}
		}
	}
	for (int i = 0; i <= sum / 2; i++)
	{
		(ext += dp[i]) %= mod;
	}
	(ext *= 3) %= mod;
	if (sum % 2 == 0)
	{
		ext += mod * 3;
		(ext -= dp2[sum / 2] * 3) %= mod;
	}
	ans = pow(3, n) + mod - ext;
	ans %= mod;
	cout << ans << endl;
	cin >> n;
}


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

int main(){
    
    int N;
    cin >> N;
    string S;
    cin >> S;
    
    int contW = 0;
    int W[N];
    W[0] = 0;
    for(int i = 1; i < N;i++){
        if(S[i-1]=='W')contW++;
        W[i] = contW;
        
    }
    
    
    int contE = 0;
    int E[N];
    E[N-1] = 0;
    for(int i = N - 2; i >= 0;i--){
        if(S[i+1]=='E')contE++;
        E[i] = contE;
        
    }
    
    int ans = N;
    for(int i = 0; i < N ;i++){
        
        ans = min(ans,E[i] + W[i]);
        
    }
    cout << ans << endl;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define LINF 1e18
#define INF 1e9
#define P pair<ll,ll>
#define fs first
#define sc second
using namespace std;

int main(){
  ll n,m,ans = 0;
  cin >> n >> m;
  bool check[n] = {};
  ll x[m],y[m],cnt[n] = {};
  rep(i,0,m) cin >> x[i] >> y[i];

  check[0] = true;
  rep(i,0,n) cnt[i] = 1;

  rep(i,0,m){
    if(check[x[i]-1]) check[y[i]-1] = true;
    cnt[x[i]-1]--; cnt[y[i]-1]++;

    if(!cnt[x[i]-1]) check[x[i]-1] = false;
  }

  rep(i,0,n){
    if(check[i] && cnt[i]) ans++;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2688
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

N,M = map(int,input().split())

red = set([1])
pos = [0] + [1] * N
for m in range(M):
    x,y = map(int,input().split())
    if x in red:
        red.add(y)
        if pos[x] == 1:
            red.remove(x)
    pos[x] -= 1
    pos[y] += 1
        
print(len(red))


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

int main() {
  int k,x;
  cin>>k>>x;

  for(int i=x-k+1; i<x+k-1; i++) {
    cout<<i<<' ';
  }
  cout<<x+k-1<<endl;

  return 0;
}

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

vector<long long> item;
map<long long, long long> factor;
long long MOD = 1000000007;

long long modpow(long long a, long long p){
	if(p == 1) return a;
	long long adash = a * a % MOD;
	if(p % 2) return modpow(adash, p / 2) * a % MOD;
	return modpow(adash, p / 2);
}

void factorize(long long M){
	long long m = M;
	for(long long i=2;i*i<=M;i++){
		int check = 0;
		while(m % i == 0){
			factor[i]++;
			m /= i;
			check = 1;
		}
		if(check) item.push_back(i);
	}
	if(m != 1){
		factor[m] = 1;
		item.push_back(m);
	}
}

long long combination(long long N, long long K){
	if(K == 0) return 1;
	if(N == K) return 1;
	if(K > N - K) return combination(N, N - K);
	long long ans = 1;
	long long div = 1;
	for(long long i=1;i<=K;i++){
		ans *= N - i + 1;
		ans %= MOD;
		div *= i;
		div %= MOD;
	}
	return ans * modpow(div, MOD - 2) % MOD;
}
int main(){
	long long N, M;
	cin >> N >> M;
	factorize(M);
	long long ans = 1;
	for(int i = 0;i<(int)item.size();i++){
		ans *= combination(N - 1 +  factor[item[i]], factor[item[i]]);
		ans %= MOD;
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<climits>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reg(i,a,b) for(int i=(a);i<=(b);i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=(b);i>=(a);i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX


int cs[20][20];

char dats[20][25];
int n;

bool isin(char* p,char* q){
	int lp = strlen(p);
	int lq = strlen(q);
	rep(i,lp){
		if(i+lq>lp)break;
		rep(j,lq){
			if(p[i+j]!=q[j])goto nexti;
		}
		return true;
nexti:;
	}
	return false;
}

int addlen(char* p,char* q){
	int lp = strlen(p);
	int lq = strlen(q);
	
	int minl = lq;
	rep(i,lp){
		int j=0;
		rep(j,lq){
			if(i+j>=lp)break;
			if(p[i+j]!=q[j])goto nexti;
		}
		return lq + i - lp;
nexti:;
	}
	return lq;
}


int dp[1<<15][20];




int main(void){
	
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		memset(dp,-1,sizeof(dp));
		
		char id[20][25];
		rep(i,n){
			scanf("%s",id[i]);
		}
		
		int tn = 0;
		rep(i,n){
			bool issub = false;
			rep(j,n){
				if(i==j)continue;
				if(isin(id[j],id[i]))issub = true;
			}
			if(issub==false){
				strcpy(dats[tn],id[i]);
				tn++;
			}
		}
		
		n = tn;
		
		rep(i,n){
			rep(j,n){
				if(i==j)cs[i][j]=0;
				else{
					cs[i][j] = addlen(dats[i],dats[j]);
					//printf("%2d %s %s\n",cs[i][j],dats[i],dats[j]);
				}
			}
		}
		
		
		rep(i,n){
			dp[0][i]=0;
		}
		
		rep(i,1<<n){
			rep(j,n){
				if( ((1<<j)&i) == 0)continue;
				int fi = i-(1<<j);
				if(fi == 0){
					dp[i][j] = strlen(dats[j]);
				}
				else{
					dp[i][j] = IINF;
					rep(k,n){
						if(dp[fi][k]==-1)continue;
						dp[i][j] = min(dp[i][j] , dp[fi][k] + cs[k][j]);
					}
				}
			}
		}
		
		int ans = IINF;
		rep(i,n){
			ans = min(ans,dp[(1<<n)-1][i]);
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, n) for(ll i=0; i<n; i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7;
ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}
ll LCM(ll x, ll y) { 
  return x / GCD(x, y) * y;
}

int main(){
  int n, q;
  ll k;
  cin >> n >> k >> q;
  vector<vector<int>> count(n, vector<int> (0));
  rep(i, q) {
    int a; cin >> a;
    count[a-1].push_back(1);
  }
  rep(i, n) {
    if(q - count[i].size() < k) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}


Measured memory_bytes: 4992
/*input
6 0
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m; cin >> n >> m;
    vector<bool> ac(n + 1, 0);
    vector<int> penalty(n + 1, 0);
    int done = 0;
    int finalpen = 0;
    for(int i = 0; i < m; i++)
    {
    	int p; cin >> p;
    	string s; cin >> s;
    	if(s == "AC" && !ac[p])
    	{
    		done++;
    		ac[p] = 1;
    	}
    	else if(s == "WA" && !ac[p]) penalty[p]++;
    }
    cout << done << ' ';
    for(int i = 1; i < n + 1; i++) if(ac[i]) finalpen += penalty[i];
    cout << finalpen;

    return 0;
}

Measured memory_bytes: 640
n, k, q = map(int, input().split())
A = []
for i in range(q):
  A.append(int(input()))
  
po = [0]*n

for i in A:
  po[i-1] += 1
  
for i in po:
  if i > q-k:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 8640
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
LL fact[N];
LL rfact[N];
int dp[N][32];
void init()
{
	fact[0] = 1;
	for (int i = 1; i < N; i++) fact[i] = fact[i - 1] * i % INF;
	rfact[0] = rfact[1] = 1;
	for (int i = 2; i < N; i++) rfact[i] = (INF - INF / i) * rfact[INF % i] % INF;
	for (int i = 2; i < N; i++) rfact[i] = rfact[i - 1] * rfact[i] % INF;
}
LL C(LL n, LL m)
{
	if (n < m) return 0;
	return fact[n] * rfact[m] % INF * rfact[n - m] % INF;
}
map<int, vector<int>> mv;
int n, m;
LL ans = 0;
void dfs(int cur, int cnt = 1)
{
	if (cur == m)
	{
		ans += C(n, cnt);
		if (ans >= INF) ans -= INF;
		return;
	}
	for (auto& y : mv[cur])
	{
		dfs(y, cnt + 1);
	}
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	init();
	cin >> n >> m;
	if (m == 1) puts("1"), exit(0);
	vector<int> v;
	for (int i = 1; i * i <= m; i++)
	{
		if (m % i) continue;
		v.push_back(i);
		if (i * i != m) v.push_back(m / i);
	}
	sort(v.begin(), v.end());
	v.erase(v.begin());
	for (int i = 0; i < v.size(); i++)
	{
		dp[i][1] = 1;
		for (int j = i + 1; j < v.size(); j++)
		{
			if (v[j] % v[i]) continue;
			for (int k = 1; k < 32; k++)
			{
				dp[j][k] += dp[i][k - 1];
				if (dp[j][k] >= INF) dp[j][k] -= INF;
			}
		}
	}
	int sz = v.size() - 1;
	for (int i = 1; i < 32; i++)
	{
		ans = (ans + C(n, i) * dp[sz][i]) % INF;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3968
#include <iostream>
#include <cassert>

template<int Modulus>
struct modint {
	using value_type = int;

	static constexpr int mod = Modulus;
	static_assert(mod > 1, "Modulus must be greater than 1");

private :
	value_type x;

	template<class T>
	static constexpr value_type normalize (T value) noexcept {
		if (value < 0) {
			value = (-value) % mod;
			return (value ? value : mod - value);
		}
		return (value % mod);
	}

public :
	explicit constexpr modint () noexcept : x(0) { }

	template<class T>
	constexpr modint (T value) noexcept : x(normalize(value)) { }

	constexpr modint operator+ () const noexcept {
		return modint(*this);
	}

	constexpr modint operator- () noexcept {
		if (x != 0) x = mod - x;
		return modint(*this);
	}

	constexpr modint &operator+= (const modint &p) noexcept {
		if ((x += p.x) >= mod) x -= mod;
		return (*this);
	}

	constexpr modint &operator-= (const modint &p) noexcept {
		if ((x += mod - p.x) >= mod) x -= mod;
		return (*this);
	}

	constexpr modint &operator*= (const modint &p) noexcept {
		x = (int)(1LL * x * p.x % mod);
		return (*this);
	}

	constexpr modint &operator/= (const modint &p) noexcept {
		return ((*this) *= p.inverse());
	}

	constexpr modint operator+ (const modint &p) const noexcept {
		return (modint(*this) += p);
	}

	constexpr modint operator- (const modint &p) const noexcept {
		return (modint(*this) -= p);
	}

	constexpr modint operator* (const modint &p) const noexcept {
		return (modint(*this) *= p);
	}

	constexpr modint operator/ (const modint &p) const noexcept {
		return (modint(*this) /= p);
	}

	constexpr bool operator== (const modint &p) const noexcept {
		return (x == p.x);
	}

	constexpr bool operator!= (const modint &p) const noexcept {
		return (x != p.x);
	}

	constexpr modint pow (long long exp) const noexcept {
		modint value(1), buff(x);
		while (exp) {
			if (exp & 1) value *= buff;
			buff *= buff;
			exp >>= 1;
		}
		return value;
	}

	constexpr modint inverse () const noexcept {
		return pow(mod - 2);
	}

	friend std::ostream &operator<< (std::ostream &os, const modint &p) {
		return (os << p.x);
	}

	friend std::istream &operator>> (std::istream &is, modint &p) {
		long long v;
		is >> v;
		p = modint(v);
		return (is);
	}

};

#include <bits/stdc++.h>
struct fastio { fastio() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } _fastio_;
template<class T> bool chmin (T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> bool chmax (T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }

constexpr int MOD = 1'000'000'007;

int main() {
	int n;
	std::cin >> n;
	std::vector<modint<MOD>> a(n), s(n + 1, 0);
	for (int i = 0; i < n; i++) {
		std::cin >> a[i];
		s[i + 1] = s[i] + a[i];
	}
	
	modint<MOD> ans = 0;
	for (int i = 0; i < n; i++) {
		modint<MOD> sum = s[n] - s[i + 1];
		ans += (sum * a[i]);
	}
	
	std::cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 4780
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

const int MOD = 1000000007;

int main(){
  int n,m; cin >> n >> m;
  vector<ll> x(n),y(m);
  rep(i,n) cin >> x[i];
  rep(i,m) cin >> y[i];
  
  ll sum_x = 0,sum_y = 0;
  
  rep(i,n){
    sum_x += x[i] * (i-(n-1)+i);
    sum_x %= MOD;
  }
  rep(i,m){
    sum_y += y[i] * (i-(m-1)+i);
    sum_y %= MOD;
  }
  
//  printf("%d, %d\n",sum_x,sum_y);
  cout << (sum_x * sum_y) % MOD << endl;
  
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define N 300100
#define MOD 998244353
#define fn(i,n) for(int i=0;i<n;i+=1)
#define rep(i,l,r) for(int i=l;i<=r;i+=1)
#define INF 10000000000000000
#define pii pair<int,int>
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

signed main()
{
  int n;cin>>n;
  int a;
  int A[n+1];
  for (int i=0;i<n;i++)
  {
  	cin>>a;
  	A[i]=a;
  }
int dis[n];
dis[1]=0;
dis[2]=abs(A[1]-A[0]);
for (int i=3;i<n+1;i++)
{
	dis[i]=min(dis[i-1]+abs(A[i-1]-A[i-2]),dis[i-2]+abs(A[i-1]-A[i-3]));
}
       
	cout<<dis[n];
	return 0;
	
}


Measured memory_bytes: 1792
#include<bits/stdc++.h> 
using namespace std;
long long s,ans;
int n,a[200003];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    	cin>>a[i];
    sort(a+1,a+1+n);
    for(int i=2;i<=n;i++)
	{
        s=(s+a[i-1])%1000000007;
        ans=(ans+s*a[i])%1000000007;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4344
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main() {
  string s;
  cin >> s;
  int n = s.size(), i, j, ans = 0;
  bool check;
  for (i = n - 2; i > 0;) {
    check = true;
    for (j = 0; j < i / 2; j++) {
      if (s[j] != s[i / 2 + j]) {
        check = false;
      }
    }
    if (check == true) {
      cout << i << "\n";
      return 0;
    }
    i = i - 2;
  }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    long long n,k;
    cin >> n >> k;
    long long ans;
    if(k%2==0){
        long long a=n/(k/2);
        if(a%2==0){
            ans=(a/2)*(a/2)*(a/2)*2;
        }else{
            ans=((a+1)/2)*((a+1)/2)*((a+1)/2)+((a-1)/2)*((a-1)/2)*((a-1)/2);
        }
    }else{
        long long b=n/k;
        ans=b*b*b;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)

debug_mode = True if len(sys.argv) > 1 and sys.argv[1] == "-d" else False
if debug_mode:
    import os
    infile = open(os.path.basename(__file__).replace(".py", ".in"))

    def input():
        return infile.readline()


# ==============================================================


def main():
    a, b, c = list(map(int, input().strip().split()))
    s = sum((a, b, c))
    x = max(a, b, c)
    steps = 0
    while True:
        if s + steps * 2 == 3 * x:
            break
        elif s + steps * 2 < 3 * x:
            steps += 1
        elif s + steps * 2 > 3 * x:
            x += 1
    print(steps)


main()

# ==============================================================

if debug_mode:
    infile.close()


Measured memory_bytes: 3064
n = gets.chop.to_i
A = gets.chop.split.map(&:to_i)


if n < 4
  p 0
  exit
end

h = Hash.new(0)
A.sort!.reverse!


A.each do |i|
  h[i] += 1
end

h = h.to_a.sort_by!{ |x| [x[0],x[1]]}.reverse!


first_num = 0
second_num = 0

h.each do |a, b|
  if b >= 4 and first_num == 0
    first_num = a
    second_num = a
    break
  end

  if b >=4 and first_num != 0 and second_num == 0
    second_num = a
    break
  end

  if b >= 2 and first_num != 0
    second_num = a
    break
  end

  if b >= 2 and first_num == 0
    first_num = a
  end
end

p first_num * second_num






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

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr <<">>>>>>"<< #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif


int main()
{
	
	int n,m;
	string s;
	cin>>n>>m;
	while(n--){cin>>s;cout<<s<<endl<<s<<endl;}
	
}



Measured memory_bytes: 3612
s = int(input())
a = [0] * 1000001
a[1] = s

a_set = set([s])

def func(n):
    if n % 2 == 0:
        return n // 2
    else:
        return 3 * n + 1

for i in range(2, 1000001):
    a[i] = func(a[i - 1])
    a_set.add(a[i])
    if len(a_set) < i:
        print(i)
        exit()

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

typedef long long ll;

ll get(ll n, ll b) {
	if (n < b) {
		return n;
	}
	return get(n / b, b) + n % b;
}

int main(void) {
	ll n, s;
	scanf("%lld%lld", &n, &s);
	for (ll b = 2; b * b <= n; ++b) {
		// std::cerr << b << '\n';
		if (get(n, b) == s) {
			printf("%lld\n", b);
			return 0;
		}
	}
	std::vector<ll> a;
	for (ll b = 1; b * b <= n - s; ++b) {
		if ((n - s) % b == 0) {
			a.push_back(b + 1);
			a.push_back((n - s) / b + 1);
		}
	}
	// a.push_back(n);
	a.push_back(n + 1);
	std::sort(a.begin(), a.end());
	for (auto b : a) {
		if (b <= 1) {
			continue;
		}
		if (get(n, b) == s) {
			printf("%lld\n", b);
			return 0;
		}
	}
	printf("-1\n");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<queue>
#include<functional>
#include<map>
using namespace std;
int p[1 << 26], dp[200009], a[200009], c[200009]; string S;
int main() {
	for (int i = 0; i < (1 << 26); i++)p[i] = (1 << 30);
	cin >> S;
	for (int i = 0; i < S.size(); i++) { c[i] = (S[i] - 'a'); }
	for (int i = 0; i < 26; i++) {
		int V = 0;
		for (int j = 0; j <= S.size(); j++) {
			if (c[j] == i)V++; V %= 2;
			a[j + 1] += (1 << i)*V;
		}
	}
	p[0] = 0; dp[0] = 0;
	for (int i = 1; i <= S.size(); i++) {
		int minx = (1 << 30);
		for (int j = 0; j < 26; j++) {
			minx = min(minx, p[a[i] ^ (1 << j)]);
		}
		minx = min(minx, p[a[i]]);
		dp[i] = minx + 1; p[a[i]] = min(p[a[i]], minx + 1);
	}
	cout << dp[S.size()] << endl;
	return 0;
}

Measured memory_bytes: 265092
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
 
signed main(){
    int N,M;
    cin>>N>>M;
    if(N*2==M) cout <<N<<endl;
    if(N*2>M) cout<<M/2<<endl;
    if(N*2<M) cout<<N+(M-2*N)/4<<endl;
}

Measured memory_bytes: 256