akhauriyash/Code-Regression huggingface dataset:
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <tuple>
#include <cstring>
#include <queue>
using namespace std;
using ll = long long int;

const ll MOD = 1000000007;
const int SIZE = 26;

struct PMA {
  PMA* node[SIZE + 1];
  vector<int> matched;
  PMA() { memset(node, 0, sizeof(node)); }

  vector<int> unite(const vector<int> &a, const vector<int> &b) {
    vector<int> ret;
    set_union(a.begin(), a.end(), b.begin(), b.end(), back_inserter(ret));
    return ret;
  }

  void build(vector<string> pattern) {
    PMA* root = this;
    root -> node[SIZE] = root;
    for(size_t i=0; i<pattern.size(); i++) {
      PMA* now = root;
      for(size_t j=0; j<pattern[i].size(); j++) {
        int c = pattern[i][j] - 'a';
        if(!now -> node[c]) {
          now -> node[c] = new PMA;
        }
        now = now -> node[c];
      }
      now -> matched.push_back(i);
    }

    queue<PMA*> que;
    for(int i=0; i<SIZE; i++) {
      if(!root -> node[i]) root -> node[i] = root;
      else {
        root -> node[i] -> node[SIZE] = root;
        que.push(root -> node[i]);
      }
    }

    while(que.size()) {
      PMA* now = que.front(); que.pop();
      for(int i=0; i<SIZE; i++) {
        if(now -> node[i]) {
          PMA* nxt = now -> node[SIZE];
          while(!nxt -> node[i]) nxt = nxt -> node[SIZE];

          now->node[i]->node[SIZE] = nxt->node[i];
          now->node[i]->matched=unite(now->node[i]->matched, nxt->node[i]->matched);
          que.push(now->node[i]);
        }
      }
    }
  }

  ll solve(const string s, vector<string> pattern) {
    PMA* pma = this;

    int N = s.length();
    vector<ll> dp(N+1);
    dp[0] = 1;
    for(size_t i=0; i<s.length(); i++) {
      int c = s[i] - 'a';
      while(!pma -> node[c]) pma = pma -> node[SIZE];

      pma = pma -> node[c];
      for(size_t j=0; j<pma->matched.size(); j++) {
        int r = i+1, l=r-pattern[ pma->matched[j] ].length();
        (dp[r] += dp[l]) %= MOD;
      }
    }

    return dp[N];
  }
};

int main() {
  int N; cin >> N;
  vector<string> pats(N);
  for(int i=0; i<N; i++) {
    cin >> pats[i];
  }

  string text; cin >> text;
  PMA pma;
  pma.build(pats);

  cout << pma.solve(text, pats) << endl;
  return 0;
}


Measured memory_bytes: 54180
#include <stdio.h>
#include <string.h>

int main(void) {
	int i,n,a;
	long sum = 0;
	int max, min;
	
	scanf("%d",&n);
	for (i=0; i<n; i++) {
		scanf("%d",&a);
		sum += a;
		if(i==0) {
			min = a;
			max = a;
		} 
		if(a > max) {
			max = a;
		}else if(a < min) {
			min = a;
		}
	}
	
	printf("%d %d %ld\n", min, max, sum);
	
	return 0;
	
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100//000000000
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,P>
#define T tuple<int,int,int> //tuple<ll,ll,ll>
#define pr(x) cout << x << endl;
using namespace std;

int main(){
 int n,a,b; cin >> n >> a >> b;
 cout << min(n*a,b) << endl;
return 0;
}


Measured memory_bytes: 3596
sx, sy, tx, ty = [int(x) for x in input().split()]

tx -= sx
ty -= sy

print((
("U"*ty)+("R"*tx)+
("D"*ty)+("L"*tx)+
"L"+ ("U"*(ty+1))+("R"*(tx+1))+ "D"+
"R"+ ("D"*(ty+1))+("L"*(tx+1))+
"U"))



Measured memory_bytes: 3060
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::input;
use proconio::marker::{Bytes, Chars};
use std::collections::*;

fn main() {
    input! {
        n:i64,
    }
    fn sum(div: i64, n: i64) -> i64 {
        let num = n / div;
        num * (1 + num) * div / 2
    }
    let ans: i64 = (1..=n).map(|x| sum(x, n)).sum();
    println!("{}", ans);
}

Measured memory_bytes: 2144
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define INF (1LL<<59)
#define MV 200001
#define LMV 21
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define emp emplace
#define whoami(x) cerr<<#x<<" "<<x<<"\n";
#define mp make_pair
#define ins insert
#define sz size

void FLASH() {ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
void SETF() {cout.ios_base::setf(ios_base::fixed);}
void UNSETF() {cout.ios_base::unsetf(ios_base::fixed);}

typedef long long ll;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<PII, int> PPII;
typedef pair<PLL, ll> PPLL;
typedef map<int, int> MII;

const int MOD = 1000000007;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct h_llint {
  static uint64_t splitmix64(uint64_t x) {    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};

struct h_pair{
  size_t operator()(const PLL&x)const{
    return hash<ll>()(((ll)x.ff)^(((ll)x.ss)<<32));
  }
};

typedef map<ll, ll> MLL;
typedef map<PII, int> MPII;
typedef map<PLL, ll> MPLL;
typedef set<int> SI;
typedef set<ll> SL;
//ordered_set = order_of_key(.)
//ordered_set = find_by_order(.)
typedef ordered_set<int> OSI;
typedef ordered_set<ll> OSL;
typedef ordered_multiset<int> MOSI;
typedef ordered_multiset<ll> MOSL;
typedef unordered_map<ll, int, h_llint> UMLI;
typedef unordered_map<ll, ll, h_llint> UMLL;
typedef unordered_map<PLL, int, h_pair> UMPI;
typedef unordered_map<PLL, ll, h_pair> UMPL;

int ar[MV];
ll arr[MV], memo[2005][2005];
vector<PLL> xdf;

ll xd(int i, int j, int n)
{
	if(i == n+1)
	return 0;
	if(memo[i][j] != -1)
	return memo[i][j];
	ll ans = 0;
	int l = j, r = i-1-j;
	ans = max({ans, xd(i+1, j+1, n) + xdf[i-1].ff * abs(l+1 - xdf[i-1].ss), xd(i+1, j, n) + xdf[i-1].ff * abs(n-r - xdf[i-1].ss)});	
	memo[i][j] = ans;
	return ans;
}

void solve(int T)
{
	memset(memo, -1, sizeof(memo));
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		ll v;
		cin>>v;
		xdf.pb({v, i});
	}
	sort(begin(xdf), end(xdf), [](PLL A, PLL B){ return (A.ff > B.ff); });	
	ll df = xd(1, 0, n);
	cout<<df<<"\n";
	return;		
}

int main(void)
{
	FLASH();
	int T;
	T = 1;

// #ifndef ONLINE_JUDGE
// 	time_t time_t1, time_t2;
// 	time_t1 = clock();
// #endif

	//cin>>T;
	while(T--)
	solve(T);

// #ifndef ONLINE_JUDGE
// 	time_t2 = clock();
// 	SETF();
// 	cout<<"Time taken: "<<setprecision(7)<<(time_t2 - time_t1)/(double)CLOCKS_PER_SEC<<"\n";
// 	UNSETF();
// #endif

	return 0;
}

Measured memory_bytes: 35256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long X;
    cin >> X;
    vector<long long> A(2001);
    for(long long i = -1000; i <= 1000; i++){
        A[i+1000] = (i*i*i*i*i);
    }

    for(long long i = 0; i < A.size(); i++){
        for(long long j = i+1; j < A.size(); j++){
            if(A[j] - A[i] == X){
                //cout << A[j] << " " << A[i] << endl;
                cout << j - 1000 << " " << i - 1000 << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 3616
def chess(h,w):
    o = ""
    for i in range(h):
        for j in range(w):
            if (i+j)%2: o+="." 
            else: o+="#"
        o+="\n"
    print o

while 1:
    h,w=map(int,raw_input().split())
    if h==w==0:break
    chess(h,w)

Measured memory_bytes: 4224
#include<iostream>
    using namespace std;
    int main()
{
        // 整数Xの入力
        int X;
        cin >> X;
        
        // 整数Aの入力
      int A;
        cin >> A;
        
        // 分岐
        if(X < A) { // XがA未満のときは0を出力する
            cout << 0 << endl;
        }
        
        else { //X >= A以上の時10を出力せよ。
            cout << 10 << endl;
        }
        
    }

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <tuple>
#include <limits>

using lli=long long;
int main(){
  int N,M;
  std::cin >> N >> M;

  std::vector<std::tuple<int,int,int>> edge_arr;
  for(int i = 0; i < M; i++){
    int a,b,c;
    std::cin >> a >> b >> c;
    a--; b--; c *= -1;
    edge_arr.push_back(std::make_tuple(a,b,c));
  }

  std::vector<lli> length_arr(N, std::numeric_limits<lli>::max());
  length_arr[0] = 0;
  for(int i = 0; i < N-1; i++){
    for(auto&& e: edge_arr){
      lli a,b,c;
      std::tie(a,b,c) = e;
      if(length_arr[a] == std::numeric_limits<lli>::max()) continue;
      length_arr[b] = std::min(length_arr[b], length_arr[a]+c);
    }
  }

  std::vector<int> loop_arr(N, false);
  for(int i = 0; i < N; i++){
    for(auto&& e: edge_arr){
      lli a,b,c;
      std::tie(a,b,c) = e;
      if(length_arr[a] == std::numeric_limits<lli>::max()) continue;
      if(loop_arr[a]) loop_arr[b] = true;
      if(length_arr[b] > length_arr[a]+c) loop_arr[b] = true;
    }
  }

  if(loop_arr[N-1]) std::cout << "inf" << std::endl;
  else std::cout << -length_arr[N-1] << std::endl;

  return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
string s;
  cin>>s;
  if(s=="SAT")cout<<1<<endl;
 if(s=="FRI")cout<<2<<endl;
 if(s=="THU")cout<<3<<endl;
 if(s=="WED")cout<<4<<endl;
 if(s=="TUE")cout<<5<<endl;
 if(s=="MON")cout<<6<<endl;
 if(s=="SUN")cout<<7<<endl;
}

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

const int nax = 1e5+3;
int n;
int dp[nax];
int a[nax];
int f(int i){
	if (i==n-1) return 0;
	if(dp[i]!=-1) return dp[i];
	int ans = abs(a[i]-a[i+1])+f(i+1);
	if(i!=n-2) ans = min(ans, abs(a[i]-a[i+2])+f(i+2));
	return dp[i]=ans;
}
int main(){
	cin>>n;
	for(int i=0; i<n; i++) cin>>a[i];
	memset(dp, -1, sizeof dp);
	cout<<f(0)<<endl;
	return 0;
}


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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()

#define uint8_t unsigned char
#define uint16_t unsigned short
#define uint32_t unsigned int
#define uint64_t unsigned long long

#define int8_t signed char
#define int16_t signed short
#define int32_t signed int
#define int64_t signed long long



using namespace std;
// #define PI 3.14159265358979323846
// cout << fixed << setprecision(20);

int main(int argc, char const* argv[])
{
    int a = 0;
    int N = 0;
    int count = 0;

    cin >> N;
    REP(i, N) {
        cin >> a;
        //cout << i+1 << ":" << a << endl;
        if ((i+1) % 2 == 1 && a % 2 == 1) {
            
            ++count;
        }
    }

    cout << count << endl;


    return 0;
}




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

int main(){
    int N, num[4]={0};
    string c;
    string s[4]={"AC", "WA", "TLE", "RE"};

    cin >> N;
    for(int i=0; i<N; i++){
        cin >> c;
        for(int j=0; j<4; j++){
            if(c == s[j]) num[j]++;
        }
    }

    for(int i=0; i<4; i++){
    cout << s[i] << " x " << num[i] << endl;
    }
}


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

namespace CSharpPractice
{
	class Program
	{
		static long GCD(long a, long b) {
			if (b == 0) return a;
			return GCD(b, a % b);
		}
		static void Main(string[] args)
		{
			string str = "";
			while ((str = Console.ReadLine()) != null)
			{
				string[] tmp = str.Split(' ');
				long a = long.Parse(tmp[0]);
				long b = long.Parse(tmp[1]);
				long gcd = GCD(a, b);
				Console.WriteLine(gcd + " " + (a * b / gcd));
			}
		}
	}
}

Measured memory_bytes: 5620
#include<bits/stdc++.h> 
using namespace std;
int main()
{
	string s;
	cin>>s;
	string n=s;
	reverse(s.begin(),s.end());
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='b') s[i]='d';
		else if (s[i]=='d') s[i]='b';
		else if (s[i]=='p') s[i]='q';
		else if (s[i]=='q') s[i]='p';
		if(s[i]!=n[i])
		{
			cout<<"No";
			return 0;
		}
	} 
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(M);
  for (int i=0; i<M; i++) cin >> A[i];
  ll sum = accumulate(A.begin(), A.end(), 0LL);
  if (N<sum) cout << -1 << endl;
  else cout << N-sum << endl;
}


Measured memory_bytes: 3668
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array

main :: IO ()
main = do
  (n:m:_) <- fmap (map read . words) getLine :: IO [Int]
  kas <- replicateM n $ map read . words <$> getLine :: IO [[Int]]
  print $ solve m kas

solve m kas = length . filter id $ map everyone [1..m]
  where
    as = map tail kas
    everyone i = all (\a -> i `elem` a) as

Measured memory_bytes: 1020
import java.util.*
import kotlin.system.exitProcess

var n = 0L
var ans = 0

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    n = sc.nextLong()
    for (i in 1..Int.MAX_VALUE) {
        dfs(i, "")
    }

}

fun dfs(rest: Int, s: String) {
    if (rest == 0) {
        if (s.toLong()> n) {
            println(ans)
            exitProcess(0)
        }
        for (v in "357") {
            if (v !in s) {
                return
            }
        }
        ans++
    } else {
        for (c in "357") {
            dfs(rest - 1, s + c)
        }
    }
}


Measured memory_bytes: 33456
#include<bits/stdc++.h>
using namespace std;
#define ll long long
double ans;
int a[200008],sum[200008];
int n,k,x,ans1,tmp;
int main(){
   cin>>n>>k;
   for(int i=1;i<=n;i++)
    {
    	cin>>a[i];
    	sum[i]=sum[i-1]+a[i];
    }
    for(int i=k;i<=n;i++)
    {
    	if(sum[i]-sum[i-k]>=ans1)
		  ans1=sum[i]-sum[i-k],tmp=i;
    }  
      for(int i=tmp-k+1;i<=tmp;i++)
    {
    	ans+=(1+a[i])/2.0;
    }  
    printf("%.12lf",ans);
	return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main { 
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int Y = sc.nextInt();
    for (int i =0; i<=N; i++) {
      for (int j =0; j<=N-i; j++) {
        int k = N - i - j;
        if (i * 10000 + j * 5000 + k * 1000 == Y) {
          System.out.println(i + " " + j + " " + k);
          return;
        }
      }
    }
    System.out.println("-1 -1 -1");  
  }
}   

Measured memory_bytes: 25300
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
long long modpow(long long x,long long n,long long mod){
    long long res = 1;
    while(n > 0) {
        if(n & 1) (res *= x) %= mod;
        (x *= x) %= mod;
        n>>=1;
    }
    return res;
}

long long modinv(long long x, long long mod){
    return modpow(x, mod - 2, mod); }
int main(){
    ll n;
    cin >> n;
    ll ans = modpow(10, n, MOD) - 2 * modpow(9, n, MOD) + modpow(8, n, MOD);
    while (ans < 0) ans += MOD;
    cout << ans << endl;
}

Measured memory_bytes: 3592
def cin():  return list(map(int,input().split()))

N = cin()[0]
a = cin()

rec = [0 for _ in range(N + 10)]

for i in reversed(range(1, N + 1)):
    cnt = 0
    tmp = i
    while(tmp <= N):
        cnt += rec[tmp]
        tmp += i
    if cnt % 2 == a[i - 1]:  continue
    else:  rec[i] = 1
        
l = []
for i in range(1, N + 1):
    if rec[i]:  l.append(i)
print(len(l))
print(*l)

Measured memory_bytes: 107384
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 666666
int n,a[SZ],sb[SZ],N,t[SZ];
int tr(int x)
{
	int u=x;
	for(int i=1;i<=x;++i) u-=sb[i];
	return u;
}
const int MOD=1e9+7;
int f[605][605][605];
int main()
{
	cin>>n;
	for(int i=1;i<=n+n;++i)
		cin>>a[i];
	for(int i=1;i<=n+n;i+=2)
		if(a[i]!=-1&&a[i+1]!=-1)
		{
			sb[a[i]]=sb[a[i+1]]=1;
		}
	ll fac=1,x=0;
	for(int i=1;i<=n+n;i+=2)
		if(a[i]!=-1&&a[i+1]!=-1)
		{
			sb[a[i]]=sb[a[i+1]]=1;
		}
		else if(a[i]==-1&&a[i+1]==-1)
		{
			N+=2; fac=fac*(++x)%MOD;
		}
		else
		{
			N+=2; t[tr(max(a[i],a[i+1]))]=1;
		}
	f[0][0][0]=1;
	for(int i=0;i<N;++i)
	{
		ll F;
		for(int j=0;j<=N;++j)
			for(int k=0;k<=N;++k) if(F=f[i][j][k])
			{
				if(t[N-i])
				{
					//(
					(f[i+1][j+1][k]+=F)%=MOD;
					//)
					if(k)
					(f[i+1][j][k-1]+=F)%=MOD;
				}
				else
				{
					//(
					(f[i+1][j][k+1]+=F)%=MOD;
					//)
					if(j)
					(f[i+1][j-1][k]+=F*(ll)j%MOD)%=MOD;
					if(k)
					(f[i+1][j][k-1]+=F)%=MOD;
				}
			}
	}
	ll ans=f[N][0][0];
	ans=ans*fac%MOD;
	ans=(ans%MOD+MOD)%MOD;
	cout<<ans<<"\n";
}


Measured memory_bytes: 864512
#include<bits/stdc++.h>
#include<vector>
#include<math.h>
#include<string.h>
using namespace std;
#define MOD 1000000007
#define MAX 200005
#define PMAX 55
#define PRECISION 0.000001
#define INF 1000000000000000000
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
vector<pair<long long,long long> > V;
long long int gcd(long long int a,long long int b)
{
    if(b==0) return a;
    else return gcd(b,a%b);
}
long long int egcd(long long int a, long long int b, long long int & x, long long int & y) {
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    long long int x1, y1;
    long long int d = egcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}
long long int ModuloInverse(long long int a,long long int n)
{
    long long int x,y;
    x=gcd(a,n);
    a=a/x;
    n=n/x;
    long long int res = egcd(a,n,x,y);
    x=(x%n+n)%n;
    return x;
}
int main()
{
    long long n,i;
    scanf("%lld",&n);
    if(n==1)
    {
        printf("1");
        return 0;
    }
    n=n*2;
    long long temp,ans=n;
    pair<long long,long long> p;
    for(i=1;i*i<=n;i++)
    {
        if(n%i) continue;
        p.first=i;
        p.second=n/i;
        V.push_back(p);
    }
    for(i=1;i<V.size();i++)
    {
        if(gcd(V[i].first,V[i].second)>1) continue;
        temp=ModuloInverse(V[i].first%V[i].second,V[i].second);
        ans=min(ans,V[i].second*ModuloInverse(V[i].second%V[i].first,V[i].first)-1);
        //printf("ans->%lld,%lld\n",ans,temp);
        swap(V[i].first,V[i].second);
        temp=ModuloInverse(V[i].first%V[i].second,V[i].second);
        ans=min(ans,V[i].second*ModuloInverse(V[i].second%V[i].first,V[i].first)-1);
        //printf("ans->%lld,%lld,%lld\n",ans,temp,V[i].second);

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


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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define intMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

string s;

int main(){
  cin >> s;
  char pre = s[0];
  string ans = "Good";
  for(int i = 1; i < 4; i++){
    if(pre == s[i])ans = "Bad";
    pre = s[i];

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
typedef long long int ll;
using namespace std;

int main()
{
    int s; cin >> s;
    vector<ll> a(1e6+1,0);
    ll tmp = s;
    ll ans = 0;
    bool stop = true;
    while(stop){
        a[tmp]++;
        ans++;
        if(a[tmp] == 2){
            stop = false;
        }
        if(tmp % 2 == 0) tmp = tmp/2;
        else tmp = 3*tmp+1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8064
#![allow(dead_code, unused_variables)]
use proconio::{fastout, input};
use std::cmp::{min,max};

#[fastout]
fn main() {
    input! {
        n: usize,
        W:usize,
    }
    let mut w = Vec::new();
    let mut v = Vec::new();
    for i in 0..n{
        input!{x:usize,y:usize}
        w.push(x);
        v.push(y);
    }
    let mv = 100000;

    let mut dp = vec![1000000010;mv+10];
    dp[0] = 0;

    for i in 0..n{
        // println!("{:?}",&dp);
        for j in 0..=mv{
            let jj = mv-j;
            if jj >= v[i]{
                dp[jj] = min(dp[jj],dp[jj-v[i]] + w[i]);
            }
        }
    }
    // let x : Vec<usize> = dp.iter().take(100).cloned().collect();
    // println!("{:?}",&x);
    let mut ans = 0;
    for i in 0..=mv{
        if dp[i] <= W{
            ans = i;
        }
    }
    println!("{}",ans);
}


Measured memory_bytes: 2804
#![allow(non_snake_case)]

use std::io;


fn main() {
    // [b][f][r]=v
    // b:棟, f:フロア, r:部屋, v:人数
    let mut people: Vec<Vec<Vec<i32>>> = vec![vec![vec![0; 10]; 3]; 4];

    let sin = io::stdin();
    let mut buf = String::new();
    sin.read_line(&mut buf).ok();
    let n: u32 = buf.trim().parse().unwrap();

    for _ in 0..n {
        let mut buf = String::new();
        sin.read_line(&mut buf).ok();
        let mut ws = buf.split_whitespace();

        let b: usize = ws.next().unwrap().parse().unwrap();
        let f: usize = ws.next().unwrap().parse().unwrap();
        let r: usize = ws.next().unwrap().parse().unwrap();
        let v: i32 = ws.next().unwrap().parse().unwrap();

        people[b-1][f-1][r-1] += v;
    }

    for b in 0..4 {
        for f in 0..3 {
            for r in 0..10 {
                print!(" {}", people[b][f][r]);
            }
            println!("");
        }
        if b == 3 {
            break;
        }
        for _ in 0..20 {
            print!("#");
        }
        println!("");
    }
}



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

int main(){
    string s, t;
    int a, b;
    string u;
    cin >> s >> t >> a >> b >> u;

    if(s==u) cout << a-1 << " " << b << endl;
    else if(t==u) cout << a << " " << b-1 << endl;
}

Measured memory_bytes: 3628
fun main(args: Array<String>){
    val (a, b) = readLine()!!.split(" ").map { it.toInt() }
    for(i in 0..1000){
        if((i * 0.08).toInt() == a && (i * 0.1).toInt() == b){
            println(i)
            return
        }
    }
    println(-1)
}

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int n,a,b,c,d;
string s;
int main() {
    cin>>n>>a>>b>>c>>d;
    cin>>s;

    int from = a-1;
    int to = max(c,d)-1;
    bool passover = false;

    FOR(i,from, to-1){
        if((s[i]=='#' && s[i+1]=='#') || (s[i+1]=='#' && s[i+2]=='#')){
            cout << "No" << endl;
            return 0;
        }

        if(i>=(b-1)-1 && i<=(d-1)-1 && s[i]=='.' && s[i+1]=='.' && s[i+2]=='.')
            passover = true;
    }

    if(d<c && !passover)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;

    return 0;
}

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

#define NIL NULL

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;

Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x; 
    if(z->key < x->key){
      x = x->left;
    }
    else{ 
       x = x->right;
    }
  }
    z->parent = y;

    if(y == NIL){ 
      root = z;
    }
    else if(z->key < y->key){
       y->left = z;
    }
    else{ 
       y->right = z;
    }
}

void inorder(Node u){

  if(u != NIL){
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
  }
}

void preorder(Node u){
  
  if(u != NIL){
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right); 
  }
}

int main(){

  int m, i, x;
  char com[20];
  
  scanf("%d", &m);

  for ( i = 0 ; i < m ; i++ ){
    scanf("%s", com);
    if ( com[0] == 'i' ){
    scanf("%d", &x);
    insert(x);
    }
    else if ( com[0] == 'p' ){
      inorder(root); 
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}

Measured memory_bytes: 24040
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;

    int black = 0;
    for (int i=0;i<S.length();i++) {
        if (S[i] == '#') black++;
    }
    int white = N - black;
    int left_black = 0;
    int ans = white;
    for (int i=0;i<S.length();i++) {
        if (S[i] == '#') left_black++;
        int num = left_black + N - black - (i+1 - left_black);
        if (ans > num) ans = num;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
int main()
{
    int n;
    scanf("%d",&n);
    int a[55],m=0;
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(int i=0;i<n;i++)
        for(int j=i+1;j<n;j++)
        m+=a[i]*a[j];
    printf("%d\n",m);
    return 0;
}








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

int main() {
  string s;
  cin>>s;
  long long ans=0;
  int a[2019],b[s.size()],c[s.size()],d[s.size()];
  for(int i=0;i<2019;i++)a[i]=0;
  a[0]=1;
  b[0]=1;
  for(int i=0;i<s.size();i++){
    d[s.size()-1-i]=s.at(i)-48;
  }
  for(int i=0;i<s.size();i++){
    if(i==0){
      a[d[0]]++;
      c[0]=d[0];
    }
    else{
      b[i]=10*b[i-1]%2019;
      c[i]=(c[i-1]+b[i]*d[i])%2019;
      a[c[i]]++;
    }
  }
  for(int i=0;i<2019;i++){
    ans+=a[i]*(a[i]-1)/2;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 6028
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = long.Parse(line[0]);
        var m = long.Parse(line[1]);
        if (m < n * 2) Console.WriteLine(m / 2);
        else
        {
            var zc = m - 2 * n;
            Console.WriteLine(n + zc / 4);
        }
    }
}

Measured memory_bytes: 11092
/**
*     => Md. Sajjat Hosen
*     => Department of Computer Science and Engineering
*     => Bangabandhu Sheikh Mujibur Rahman Science and Technology University
**/

/*..................! TRY ONCE MORE !..................*/

/*...Part - 01...*/

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

/*...Part - 02...*/

typedef long long               ll ;
typedef long double             ld ;
typedef unsigned long long      ull ;
typedef pair<int,int>           pii ;
typedef pair<ll,ll>             pll ;
typedef vector<int>             vi ;
typedef vector<ll>              vll ;
typedef vector<vector<int>>     vvi ;

int Int(){int x ; scanf("%d",&x) ; return x ;}
ll Long(){ll x ; scanf("%lld",&x) ; return x ;}
float Float(){float x ; scanf("%f",&x) ; return x ;}
double Double(){double x ; scanf("%lf",&x); return x;}

/*...Part - 03...*/
/*....Debugger....*/

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl ;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << ' ' ;
    err(++it, args...);
}

/*...Part - 04...*/
/*...Needed to change according to problem requirements...*/

const int N          = (int)2e5 + 5 ;
const int maxN       = (int)1e6 + 6 ;
const ll  Mod        = (ll)1e9 + 7 ;
const int inf        = (int)2e9 ;
const ll  Inf        = (ll)1e18 ;

/*..........................................................*/
/*...Part - 05...*/

#define     debug(x)    cerr << #x << " = " << x << '\n' ;
#define     rep(i,b,e)  for(__typeof(e) i = (b) ; i != (e + 1) - 2 * ((b) > (e))  ; i += 1 - 2 * ((b) > (e)))
#define     Int         Int()
#define     Long        Long()
#define     Float       Float()
#define     Double      Double()
#define     all(x)      x.begin() , x.end()
#define     sz(x)       (int)x.size()
#define     ff          first
#define     ss          second
#define     pb          push_back
#define     eb          emplace_back
#define     mem(a)      memset(a , 0 ,sizeof a)
#define     memn(a)     memset(a , -1 ,sizeof a)

/*...Part - 06...*/
/*...... ! Code start from here ! ......*/



int main(){
    //freopen("input.txt","r",stdin);
    int test = 1 , tc = 0 ;
    while(test--){
        int a[3];
        for(int i = 0; i < 3; i++){
            a[i] = Int;
        }
        sort(a, a + 3);
        if(a[2] == a[1] and a[1] != a[0] or a[0] == a[1] and a[1] != a[2])
            printf("Yes\n");
        else
            printf("No\n");
    }

    return 0 ;
}

/*...Always look at the part - 04...*/
/*...............END................*/


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

class Program
{
    static void Main(string[] arg){
        string[] input = Console.ReadLine().Split(' ');
        double a = double.Parse(input[0]);
        double b = double.Parse(input[1]);
        double H = double.Parse(input[2]);
        double M = double.Parse(input[3]);
        
        //長針の位置
        double deg_h = H * 30 + 30*M/60;
        double deg_m = M*360/60;

        double deg = Math.Abs(deg_h-deg_m);

        //余弦定理
        double ans;
        ans = a*a+b*b - 2*a*b*Math.Cos(Math.PI*deg/180.0);
        Console.WriteLine(Math.Sqrt(ans));
        return;
    }
}


Measured memory_bytes: 27868
import collections
s=[]
a=[]
S =  list(map(int,input().split()))
N = S[0]
K = S[1]
for i in range(1,K+1):
    d = int(input())
    A = list(map(int,input().split()))
    a.append(A)
for t in range(1,N+1):
    s.append(t)
import itertools
aa=list(itertools.chain.from_iterable(a))
c = collections.Counter(aa)
print(len(s)-len(c))

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

int n, x[20], y[20];
int m[20];
long long rlt[20], w[20];

int v[20], szv, vv[20], szvv;

void DFS(int c){
	if(c == n){
		int cn = 0;

		szv = szvv = 0;

		for(int i = 0; i < n; i ++) {
			if(m[i]) v[szv++] = i, cn ++;
			else vv[szvv++] = i;
		}

		long long r = 0;
		for(int ii = 0; ii < szvv; ii ++) {
			int i = vv[ii];

			int mn = min(abs(x[i]), abs(y[i]));
			for(int jj = 0; jj < szv; jj ++) {
				int j = v[jj];
				if(m[j] == 1) mn = min(mn, abs(x[i] - x[j]));
				else if(m[j] == 2) mn = min(mn, abs(y[i] - y[j]));
			}

			r += 1ll * mn * w[i];
			if(r > rlt[cn]) return;
		}
		for(int i = cn; i <= n; i ++) {
			if(rlt[i] > r) {
				rlt[i] = r;
			}
			else return;
		}
	}
	else{
		m[c] = 0; DFS(c + 1);
		m[c] = 1; DFS(c + 1);
		m[c] = 2; DFS(c + 1);
	}
}

int id[20], xx[20], yy[20], ww[20];

int main(){
  	srand(time(0));
	scanf("%d", &n);
	for(int i = 0; i < n; i ++){
		scanf("%d%d%lld", &xx[i], &yy[i], &ww[i]);
		id[i] = i;
	}
	random_shuffle(id, id + n);
	for(int i = 0; i < n; i ++) x[i] = xx[id[i]], y[i] = yy[id[i]], w[i] = ww[id[i]];

	memset(m, 0, sizeof(m));
	memset(rlt, 127, sizeof(rlt));

	DFS(0);

	for(int i = 0; i <= n; i ++){
		printf("%lld\n", rlt[i]);
	}
}


Measured memory_bytes: 3824
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define MAX 100000
#define INF 2140000000
#define MOD 1000000007


vector<int> p, ranki;

int find_set(int x) {
	if(x != p[x])
		p[x] = find_set(p[x]);
	return p[x];
}

void unionsets(int x, int y) {
	int xroot = find_set(x);
	int yroot = find_set(y);

	if (xroot == yroot) {
		return;
	}

	if (ranki[xroot] < ranki[yroot]) {
		int temp = xroot;
		xroot = yroot;
		yroot = temp;
	}

	p[yroot] = xroot;
	ranki[xroot] = ranki[xroot] + ranki[yroot];

	return;
}

int main() {
	int n, m, k;
	cin >> n >> m >> k;
	vector<pair<int, int> > pp;

	p.resize(n);
	ranki.resize(n);

	for (int i = 0; i < n; ++i) {
		p[i] = i;
		ranki[i] = 1;
	}

	for (int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		unionsets(a - 1, b - 1);
		pp.push_back(make_pair(a - 1, b - 1));
	}

	vector<int> ans(n, 0);

	for (int i = 0; i < n; ++i) {
		ans[i] = ranki[find_set(i)] - 1;
	}

	for (int i = 0; i < k; ++i) {
		int c, d;
		cin >> c >> d;

		if (find_set(c - 1) == find_set(d - 1)) {
			ans[c - 1]--;
			ans[d - 1]--;
		}
	}


	for (int i = 0; i < (int) pp.size(); ++i) {
		ans[pp[i].first]--;
		ans[pp[i].second]--;
	}


	for (int i = 0; i < (int) ans.size(); ++i) {
		cout << ans[i] << " ";
	}

	cout << endl;

	return 0;
}

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

int main() {
    int n; cin >> n;
    string s, t; cin >> s >> t;
    string ans = s + t;
    for (int i = n - 1; i >= 0; i--) {
        int flag = 1;
        string r;
        for (int j = 0; j < i; j++) r += s[j]; 
        for (int j = 0; j < n - i; j++) {
            if (s[i + j] != t[j]) flag = 0;
        }
        r += t;
        if (flag) ans = r;
    }
    cout << ans.size() << endl;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
n=int(input())
sum=0
min=1000001
max=-1000001
table=list(map(int,input().split(" ")))
for i in table:
    sum+=i
    if max<i:
        max=i
    if min>i:
        min=i

print(str(min)+" "+str(max)+" "+str(sum))


Measured memory_bytes: 6592
//writer：Sakura
//problem：Forest
//id：Petrozavodsk Contest 001--D
//from：AtCoder

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#define N 100005
#define inf 0x3f3f3f3f
using namespace std;

typedef long long ll;

int n,m,f[N],ok[N],ok_id[N],id[N],a[N];
bool b[N]; 
ll ans=0;

int find(int x){
	return f[x]==x?x:f[x]=find(f[x]);
}

bool cmp(int x,int y){
	return a[x]<a[y];
}
int main(){
	scanf("%d %d",&n,&m);
	int res=0;
	res=(n-1-m)*2;
	if(res>n){
		puts("Impossible");
		exit(0);
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		f[i]=id[i]=i;
		ok[i]=inf;
	}
	for(int i=1;i<=m;i++){
		int l,r;
		scanf("%d %d",&l,&r);
		++l,++r;
		f[find(l)]=find(r);
	}
	for(int i=1;i<=n;i++){
		int now=find(i);
		if(a[i]<ok[now]){
			ok[now]=a[i],ok_id[now]=i;
		}
	}
	int c=0; 
	for(int i=1;i<=n;i++){
		if(find(i)==i){
			++c;
			ans+=ok[i];
			b[ok_id[i]]=1;
			--res;
		}
	}
	if(c==1){
		puts("0");
		exit(0);
	}
	sort(id+1,id+n+1,cmp);
	for(int i=1,j=1;i<=res;i++){
		for(;b[id[j]];j++);
		ans+=a[id[j++]];
	}
	printf("%lld\n",ans);
	return 0;
}



Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=3005;

int n;
int a[N], cache[N][N][2];

int dp(int i, int j, int player)
{
	if(j<i)
		return 0;
	int &ans=cache[i][j][player];
	if(ans!=-1)
		return ans;
	if(!player)
		ans=max(a[i]+dp(i+1, j, player^1), a[j]+dp(i, j-1, player^1));
	else
		ans=min(-a[i]+dp(i+1, j, player^1), -a[j]+dp(i, j-1, player^1));
	return ans;
}

int32_t main()
{
	IOS;
	memset(cache, -1, sizeof(cache));
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	cout<<dp(1, n, 0);
	return 0;
}


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

using namespace std;

#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define nl "\n"
#define sp " "
#define int long long
#define PI 3.141592653589793
#define scanstr(s) cin>>ws; getline(cin,s);

void solve()
{
	int grid[3][3],x,y,z;
	for(int i=0;i<3;i++)
	{
		for(int j=0;j<3;j++)
		{
			cin>>grid[i][j];
		}
	}
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<3;i++)
	{
		x=grid[i][0], y= grid[i][1], z=grid[i][2];
		if(binary_search(a,a+n,x)&&binary_search(a,a+n,y)&&binary_search(a,a+n,z))
		{
			cout<<"Yes\n";
			return ;
		}
	}
	for(int i=0;i<3;i++)
	{
		x=grid[0][i], y= grid[1][i], z=grid[2][i];
		if(binary_search(a,a+n,x)&&binary_search(a,a+n,y)&&binary_search(a,a+n,z))
		{
			cout<<"Yes\n";
			return ;
		}
	}
	x=grid[0][0], y=grid[1][1], z=grid[2][2];
	if(binary_search(a,a+n,x)&&binary_search(a,a+n,y)&&binary_search(a,a+n,z))
	{
		cout<<"Yes\n";
		return ;
	}
	x=grid[0][2], y=grid[1][1], z=grid[2][0];
	if(binary_search(a,a+n,x)&&binary_search(a,a+n,y)&&binary_search(a,a+n,z))
	{
		cout<<"Yes\n";
		return ;
	}
	cout<<"No\n";
	return ;
}

int32_t main()
{
	FastIO;
	solve();
	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(begin, end) for (i=begin;i<end;i++)
#define repj(begin, end) for (j=begin;j<end;j++)
#define init(arr, end, val) for (i=0;i<end;i++) arr[i] = val;
#define printint(i0, i1) printf("%d %d\n", i0, i1)

using namespace std;
typedef long long int ll;
const int inf = 1000000000;
const int mod = 1000000007;
const int nil = -1;
int i, n, m, k, ans;
int a[1000];

int main() {
    scanf(" %d", &k);
    scanf(" %d %d", &n, &m);
    rep(n, m+1) {
        if (i%k==0) {
            printf("OK");
            exit(0);
        }
    }
    printf("NG");
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<P,P> PP;
const ll MOD=10000;
const ll INF=1000000010;
const int MAX=100001;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
    int w,n;
    cin>>w>>n;
    int c[40];
    for(int i=1;i<=w;i++){
        c[i]=i;
    }
    for(int i=0;i<n;i++){
        int a,b;
        scanf("%d,%d",&a,&b);
        swap(c[a],c[b]);
        
    }
    for(int i=1;i<=w;i++){
        cout<<c[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
#define pb push_back
#define fi first
#define se second 
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n,a,b; 
	cin>>n>>a>>b; 
	ll div = n/(a+b);
	ll mod = n%(a+b);
	ll ans = div*a;
	ans+=min(mod,a);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
s = input()[::-1]

s = s.replace("eraser"[::-1], "")
s = s.replace("erase"[::-1], "")
s = s.replace("dreamer"[::-1], "")
s = s.replace("dream"[::-1], "")

if s == "":
  print("YES")
else:
  print("NO")  

Measured memory_bytes: 9156
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,z;
	cin>>n>>m;
	for(int i=1;i<n;i++)
	{
		z=z+i;
	}
	for(int i=1;i<m;i++)
	{
		z=z+i;
	}
	cout<<z;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  string s;
  int c[3];
  cin>>s;
  string m[6];
  m[0]="abc";
  m[1]="acb";
  m[2]="bac";
  m[3]="bca";
  m[4]="cab";
  m[5]="cba";
  for(int i=0;i<6;i++){
    if(s==m[i]){
      cout<<"Yes";
      return 0;
    }
  }
  cout<<"No";
  return 0;
  }

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  long long sum = 0;
  for (int i = 0; i < k; i++) {
    sum += 1LL * a[i];
  }
  cout << sum << '\n';
}


Measured memory_bytes: 3648
line = input().split()
N, M = int(line[0]), int(line[1]) 

if M == 0:
  if N == 1:
    print(0)
  else:
    print(10**(N-1))
  quit()

conds = []
for i in range(M):
  line = input().split()
  conds.append((int(line[0]),int(line[1])))
 
NUM = [-1] * N
 
isOK = True
for curCon in conds:
  s = curCon[0]
  dig = curCon[1]
  
  if NUM[s-1] == -1:
    NUM[s-1] = dig
  elif NUM[s-1] != dig:
    isOK = False
 
if N > 1:
  if NUM[0] == 0:
    isOK = False
 
if isOK != True:
  print(-1)
  quit()
else:
  if NUM[0] == -1:
    NUM[0]=1
    
  for i in range(N):
    if NUM[i] == -1:
      NUM[i] = 0
  numChar = ""
  for iNum in NUM:
    numChar += str(iNum)
  print(int(numChar))

Measured memory_bytes: 3188
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str, T: str):
    if S == T[:-1]:
        print(YES)
    else:
        print(NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    solve(S, T)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61676
#include<bits/stdc++.h>
#define int long long
using namespace std;
int Read() {
	int x = 0, f = 1; char ch = getchar();
	while(!isdigit(ch)) {if(ch == '-')  f = -1; ch = getchar();}
	while(isdigit(ch)) {x = (x << 3) + (x << 1) + ch - '0'; ch = getchar();}
	return x * f;
}
int n, q, h[800005], L[800005], covh[800005], covL[800005];
void build(int o, int l, int r) {
	if(l == r) {
		h[o] = L[o] = n;
		return ;
	}
	int mid = (l + r) >> 1;
	build(o << 1, l, mid);
	build(o << 1 | 1, mid + 1, r);
	h[o] = min(h[o << 1], h[o << 1 | 1]);
	L[o] = min(L[o << 1], L[o << 1 | 1]);
}
void pushh(int o, int x) {
	h[o] = min(h[o], x);
	if(!covh[o])  covh[o] = x;
	covh[o] = min(covh[o], x);
}
void pushl(int o, int x) {
	L[o] = min(L[o], x);
	if(!covL[o])  covL[o] = x;
	covL[o] = min(covL[o], x);
}
void pushdown(int o) {
	if(covh[o]) {
		pushh(o << 1, covh[o]); pushh(o << 1 | 1, covh[o]);
		covh[o] = 0;
	}
	if(covL[o]) {
		pushl(o << 1, covL[o]); pushl(o << 1 | 1, covL[o]);
		covL[o] = 0;
	}
}
void modify_h(int o, int l, int r, int nl, int nr, int num) {
	if(nl <= l && r <= nr) {
		pushh(o, num);
		return;
	}
	int mid = (l + r) >> 1;
	pushdown(o);
	if(nl <= mid)  modify_h(o << 1, l, mid, nl, nr, num);
	if(mid < nr)  modify_h(o << 1 | 1, mid + 1, r, nl, nr, num);
	h[o] = min(h[o << 1], h[o << 1 | 1]);
}
void modify_l(int o, int l, int r, int nl, int nr, int num) {
	if(nl <= l && r <= nr) {
		pushl(o, num);
		return ;
	}
	int mid = (l + r) >> 1;
	pushdown(o);
	if(nl <= mid)  modify_l(o << 1, l, mid, nl, nr, num);
	if(mid < nr)  modify_l(o << 1 | 1, mid + 1, r, nl, nr, num);
	L[o] = min(L[o << 1], L[o << 1 | 1]);
}
int query_h(int o, int l, int r, int pos) {
	if(l == r)  return h[o];
	int mid = (l + r) >> 1;
	pushdown(o);
	if(pos <= mid)  return query_h(o << 1, l, mid, pos);
	else  return query_h(o << 1 | 1, mid + 1, r, pos);
}
int query_l(int o, int l, int r, int pos) {
	if(l == r)  return L[o];
	int mid = (l + r) >> 1;
	pushdown(o);
	if(pos <= mid)  return query_l(o << 1, l, mid, pos);
	else  return query_l(o << 1 | 1, mid + 1, r, pos);
}
signed main() {
	n = Read(), q = Read(); int ans = (n - 2) * (n - 2);
	build(1, 1, n);
	for(int i = 1; i <= q; i++) {
		int opt = Read(), x = Read();
		if(opt == 1) {
			int mn = query_l(1, 1, n, x);
			ans -= mn - 2;
			modify_h(1, 1, n, 2, mn - 1, x);
		}
		else {
			int mn = query_h(1, 1, n, x);
			ans -= mn - 2;
			modify_l(1, 1, n, 2, mn - 1, x);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 19028
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = 1e9 + 7;

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin >> s;
    int ans = 0;
    int cur = 0;
    REP(i, s.size())
    {
        if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') cur++;
        else cur = 0;
        ans = max(ans, cur);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
constexpr double PI = atan2(0, -1);
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, L;
    cin >> n >> L;
    double x = 0, y = 0;
    vector<int> t(n);
    for (int i = 0; i < n; ++i)
        cin >> t[i];
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            x += cos(PI * (t[i] + t[j]) / L) * (i + n - j - 1 - (j - i - 1));
            y += sin(PI * (t[i] + t[j]) / L) * (i + n - j - 1 - (j - i - 1));
        }
    }
    x /= 1.0 * n * (n - 1) * (n - 2) / 6;
    y /= 1.0 * n * (n - 1) * (n - 2) / 6;
    cout << setprecision(10) << fixed << x << " " << y << "\n";
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <numeric>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())

#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define Dev 1000000007

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    double a, b;
    cin >> a >> b;
    cout << a / b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <vector>
#include <cstdlib>

using namespace std;


int main(void) {

	int H, W;

	while (cin >> H >> W, H, W) {
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (i % 2 == 0 && j % 2 == 0)
					cout << "#";
				else if (i % 2 != 0 && j % 2 != 0)
					cout << "#";
				else
					cout << ".";
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 3068
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define ll long long int

int main() {
	int n;
	cin >> n;
	if(n % 1000 != 0) cout << 1000 - (n % 1000);
	else cout << 0;
	return 0;
}

Measured memory_bytes: 3632